fix(grid): every result grid leaks (extension-method listener on PiiMaskingController is never removed); ~5 MB per run
Les mainteneurs répondent en général sous 1 jour
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 3/5
- Temps estimé
- 1-2 jours
- Accessibilité débutants
- 55/100
- Type d'issue
- Bug
- Clarté
- Clairement spécifiée
- Activité
- Active
- Domaine
- desktop, performance
Piste de recherche
Start with the listener registration and disposal in lib/features/workspace/result_grid_view.dart, then read the extension handlers in lib/features/workspace/grid/grid_pii_masking.dart and inspect the horizontal scroll listener pair. Add a guard under test/guards/ and a widget test that disposes VirtualResultGrid and checks PiiMaskingController.instance.hasListeners; run those tests. Done means listeners are removed and the guard catches extension method tear-offs used in listener pairs.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
Problem
Every result grid that is ever shown is kept in memory for the rest of the session, together with its whole result set and its widget / render / semantics tree. Each query run and each closed tab leaks one grid.
Cause: _VirtualResultGridState registers _onPiiMaskingChanged as a listener on the app-wide singleton PiiMaskingController.instance (lib/features/workspace/result_grid_view.dart:167) and removes it in dispose() (:392), but _onPiiMaskingChanged is declared in an extension _GridPiiMasking on _VirtualResultGridState (lib/features/workspace/grid/grid_pii_masking.dart:34). In Dart, tearing off an extension method creates a new closure each time and two such closures are not equal, so removeListener(_onPiiMaskingChanged) does not find the one that addListener(_onPiiMaskingChanged) stored. The listener stays in the singleton's list and keeps the state alive forever: state -> widget -> CompactResultDataset / rows -> element tree -> render objects -> semantics.
Minimal reproduction of the language behavior:
class Owner { void inClass() {} void reg(Notifier n){ n.add(inClass); n.add(ext);} void unreg(Notifier n){ n.remove(inClass); n.remove(ext);} }
extension E on Owner { void ext() {} }
// after reg + unreg: 1 listener is left (the extension tear-off); `o.inClass == o.inClass` is true, `o.ext == o.ext` is false
Measurements
Profile build of dev 0.4.22+5, app benchmark harness, Dart heap after a forced full GC (getAllocationProfile(gc: true)), heavySql = 5000 rows x 20 columns, retaining paths from the VM service:
Re-running a query 6 more times in the same tab
live _VirtualResultGridState |
live CompactResultDataset |
Dart heap | |
|---|---|---|---|
| after 1 result | 1 | 1 | 62 MB |
| after 6 re-runs | 6 | 6 | 92.5 MB (+5 MB per run) |
Opening a tab, running the query, closing the tab (confirming "Discard & Close"), 4 times
| baseline | after 4 cycles | |
|---|---|---|
mounted QueryEditorTab / ResultsTab |
1 | 1 |
live QueryEditorTab instances |
2 | 6 |
live ResultsTab |
2 | 6 |
live VirtualResultGrid / _VirtualResultGridState |
1 | 5 |
live CompactResultDataset |
1 | 5 |
live FocusNode |
105 | 235 |
live AnimationController |
147 | 323 |
| Dart heap | 58 MB | 87-90 MB |
Retaining path of every leaked grid state (identical for all, 6 elements):
_VirtualResultGridState <- Context.0[] <- _Closure <- _List.N[] <- PiiMaskingController._listeners <- (static field PiiMaskingController.instance)
and of the leaked CompactResultDataset: _LazyDatasetRowList.dataset <- ResultsTab.rows <- _ResultsTabState._widget ... <- _VirtualResultGridState._focusNode ... <- PiiMaskingController._listeners.
A session of 100 queries on a 5000 x 20 result leaks on the order of 500 MB of Dart heap, more for larger results and a lot more for a result with a raised row cap.
Solution
- Declare
_onPiiMaskingChanged(and_onHorizontalScroll, which has the same shape) inside theStateclass instead of an extension, or keep the listener in a field:late final VoidCallback _piiListener = _onPiiMaskingChanged;and use that field for bothaddListenerandremoveListener. - A scan of
lib/found exactly these twoaddListener/removeListenerpairs whose handler is an extension method;_onHorizontalScrollis attached to a controller thatdispose()discards, so it is harmless in practice, but should be fixed the same way. - Add a guard test in
test/guards/that fails when the argument ofaddListener(/removeListener(is a method declared in anextension(the regex scan used for this report is enough).
Acceptance
-
PiiMaskingController.instancehas no listeners after aVirtualResultGridis disposed (widget test: pump the grid, remove it, asserthasListeners == false). - 6 re-runs of the same query in one tab leave 1 live
_VirtualResultGridState(check with a leak test orleak_tracker). - Closing a tab releases
QueryEditorTab,ResultsTab, the grid and its dataset. - Heap after N re-runs is flat in the app benchmark (add a
leak_rerunscenario that prints live-instance counts after GC).
Related: #1549, #1552 (memory of the result path).
- Langage dominant
- Dart
- Étoiles
- 23
- Forks
- 1
- Merge moyen
- 31 min
- PR mergées (30 j)
- 570
Préparer son environnement
Lance le conteneur de développement du projet dans votre navigateur, avec votre propre compte GitHub.
- Aucun Dockerfile ni fichier Docker Compose
- Propose un modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de QueryaHub/Querya-Desktop
-
enhancement ui
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
QueryaHub/Querya-Desktop#1689 ·
Les mainteneurs répondent en général sous 1 jour
-
ui(dialogs): make destructive query and DML preview dialogs adaptive and prevent table name overflowOuvertebug frontend
Difficulté 2/5 1-3 heures Accessibilité débutants 82/100
QueryaHub/Querya-Desktop#1642 ·
Les mainteneurs répondent en général sous 1 jour
-
bug error-handling settings
Difficulté 1/5 1-3 heures Accessibilité débutants 78/100
QueryaHub/Querya-Desktop#1637 ·
Les mainteneurs répondent en général sous 1 jour
-
enhancement
Difficulté 1/5 Moins d'une heure Accessibilité débutants 88/100
QueryaHub/Querya-Desktop#1636 ·
Les mainteneurs répondent en général sous 1 jour
-
enhancement marketplace
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
QueryaHub/Querya-Desktop#1635 ·
Les mainteneurs répondent en général sous 1 jour
Toutes les issues de QueryaHub/Querya-Desktop
Issues similaires
-
enhancement
Difficulté 2/5 1-3 heures Accessibilité débutants 64/100
0niel/university-app#617 ·
Les mainteneurs répondent en général sous 1 jour
-
enhancement
Difficulté 2/5 1-3 heures Accessibilité débutants 70/100
linagora/tmail-flutter#5010 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
bug
Difficulté 1/5 Moins d'une heure Accessibilité débutants 65/100
chriskelly/wish-together#36 ·
Les mainteneurs répondent en général sous 1 jour
-
[Bug] Web Guide has broken linksOuverte
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
AppFlowy-IO/AppFlowy#9075 ·
-
[web] Semantics `lang` attribute uses `Locale.toString()`, producing invalid tags like `es_US`Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
Les mainteneurs répondent en général sous 1 jour