Skip to content

fix(grid): result grids leak through a PiiMaskingController listener (#1555) - #1597

Merged
ZhuchkaTriplesix merged 2 commits into
devfrom
issue/1555-grid-listener-leak
Oct 15, 2026
Merged

ZhuchkaTriplesix merged 2 commits into
devfrom
issue/1555-grid-listener-leak

Conversation

@ZhuchkaTriplesix

Copy link
Copy Markdown
Member

Summary

`_onPiiMaskingChanged` (and `_onHorizontalScroll`) are declared in extensions on `_VirtualResultGridState`. A torn-off extension method is a new closure on every access, so `removeListener(_onPiiMaskingChanged)` never removed what `addListener(_onPiiMaskingChanged)` stored. The app-wide `PiiMaskingController.instance` kept every grid state, its dataset and its render tree alive (~5 MB per query run).

The handlers are now kept once in `late final` fields and those closures go to both `addListener` and `removeListener`.

Tests added (not run locally; CI will)

  • `test/features/workspace/result_grid_listener_leak_test.dart`: after the grid is removed, `PiiMaskingController.instance` has the same listeners as before.
  • `test/guards/no_extension_method_listeners_test.dart`: fails when an extension method is passed to `addListener` / `removeListener`.

Not done here

The acceptance item for a `leak_rerun` scenario in the app benchmark (live-instance counts after GC, flat heap over N re-runs) is left for a follow-up; it needs the VM-service harness and a profile build.

Closes #1555

…d is disposed

_onPiiMaskingChanged and _onHorizontalScroll are extension methods, and a
torn-off extension method is a new closure on every access, so
removeListener never matched what addListener stored. The singleton kept
every grid state (and its dataset and render tree) alive: ~5 MB per run.

Both handlers are now stored once in late final fields and those are passed
to addListener / removeListener. A widget test checks the singleton has no
leftover listener after dispose, and a guard test fails if an extension
method is ever passed to addListener / removeListener again.

Closes #1555
@github-actions github-actions Bot added bug Something isn't working performance Theme parser epic label: performance stability Theme parser epic label: stability data-grid Interactive data grid, cell editor, filtering, groupings P1 High priority / Core capability labels Oct 15, 2026
The explanation next to the new listener fields quotes
addListener(_onPiiMaskingChanged), which the scan flagged.
@ZhuchkaTriplesix
ZhuchkaTriplesix merged commit 64df031 into dev Oct 15, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working data-grid Interactive data grid, cell editor, filtering, groupings P1 High priority / Core capability performance Theme parser epic label: performance stability Theme parser epic label: stability

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant