Enable dispose-class-fields and dispose-fields lints to resolve memory leaks#9857
Enable dispose-class-fields and dispose-fields lints to resolve memory leaks#9857kenzieschmoll wants to merge 4 commits into
dispose-class-fields and dispose-fields lints to resolve memory leaks#9857Conversation
|
|
||
| class KeyboardShortcutsState extends State<KeyboardShortcuts> | ||
| with AutoDisposeMixin { | ||
| // ignore: dispose-fields, false positive. Disposed via autoDisposeFocusNode. |
There was a problem hiding this comment.
@incendial FYI several false positives in this PR when the object is disposed by another layer of abstraction.
There was a problem hiding this comment.
Thanks, I've went though all the cases and I believe the vast majority is fixed (the only tricky one left is with applyToFeatureControllers). Fixes will be in 1.38.0 which ships today
There was a problem hiding this comment.
Code Review
This pull request enables the dispose-class-fields and dispose-fields lints and adds proper disposal logic across various controllers, states, and widgets in DevTools to prevent memory leaks. The review feedback highlights several critical issues and improvement opportunities: manually calling dispose() on a State object should be avoided; a shared DragAndDropManager should not be prematurely disposed of inside an individual widget's lifecycle; potential null pointer exceptions when removing an overlay entry must be resolved; and fields should remain non-nullable rather than being made nullable solely to be nulled out during disposal, which avoids unnecessary null assertions.
| static final tabs = [analysisTab, diffTab]; | ||
|
|
||
| // ignore: dispose-fields, screen controller disposal is handled by the [ScreenControllers] class. | ||
| late AppSizeController controller; |
There was a problem hiding this comment.
@incendial is there also a way to detect when a class is not the owner of an object and therefore should not be responsible for disposing it?
There was a problem hiding this comment.
That should be fixed as well
Resolves not disposed memory leaks across devtools. Enables two new lints from DCM.