There’s no official lint that checks that .dispose() is called for classes that define or inherit a dispose() method. I bet it’s because:
The lint could be quite slow
There’s no fool-proof way to implement it (sometimes, you don’t need to run dispose(), or you call it from a different place than where you instantiate the class)
For posterity, here’s my thinking of how it would work.
Find a class Foo that has a void dispose() or a Future<void> dispose() method.
Find libraries (Dart files) in which Foo is instantiated (... = Foo();).
Ensure that there is at least one place where .dispose() is called on an instance of Foo.
This has obvious problems (what if I pass Foo.new to somewhere? what if I call dispose() in one code path but not the other?). But even in this form, I think it has a potential to find some bugs.
Ok, so I’m reporting back. leak_tracker is great and way more powerful than a lint could ever be. The DevExp is not great (or I’m too dumb to understand it) but with a little bit of tweaking, I was able to find several memory leaks in a relatively small app.
Thanks again, Loic, for bringing it up!
FWIW, I think leak_tracker probably deserves more hype.
Using contents of this forum for the purposes of training proprietary AI models is forbidden. Only if your AI model is free & open source, go ahead and scrape. Flutter and the related logo are trademarks of Google LLC. We are not endorsed by or affiliated with Google LLC.