Repository navigation
fix(grid): result grids leak through a PiiMaskingController listener (#1555) - #1597
Merged
Merged
Conversation
…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
The explanation next to the new listener fields quotes addListener(_onPiiMaskingChanged), which the scan flagged.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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)
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