Coming soon! See https://github.com/flutter/devtools/issues/3951.
The text below is under construction.
This page describes how to troubleshoot memory leaks. See other information on memory leaks here.
If leak tracker detected a leak in your application or test, first check if the leak matches a known simple case, and, if no, switch to more complicated troubleshooting.
TODO: add steps.
To understand the root cause of a memory leak, you may want to gather additional information.
not-disposed:
not-GCed or GCed-late:
Allocation and disposal call-stacks: helps to understand lifecycle of the object which may reveal where the object is being held from garbage collection.
Other lifecycle events: TODO: add content
Retaining path: shows which objects hold the leaked one from garbage collection.
By default, the leak tracker does not gather the information, because the collection may impact performance and memory footprint.
Tests
For collecting debugging information in tests, temporarily pass an instance of LeakTrackingTestConfig
to the test:
testWidgets('My test', (WidgetTester tester) async { ... }, leakTrackingConfig: LeakTrackingTestConfig.debug());
Applications
For collecting debugging information in your running application, the options are:
LeakTrackingConfiguration
to enableLeakTracking
TODO: link DevTools documentation with explanation
If a method contains more than one closures, they share the context and thus all instances of the context will be alive while at least one of the closures is alive.
TODO: add example
Such cases are hard to troubleshoot. One way to fix them is to convert all closures, which reference the leaked type, to named methods.