Coming soon! See https://github.com/flutter/devtools/issues/3951.
The text below is under construction.
This page describes motivation behind memory leak tracking. Read more about leak tracking in overview.
In most cases, an object's lifecycle is managed well by the Dart garbage collector.
However, some objects (memory-risky objects) require special care to avoid the risk of memory leaks:
Such objects usually have a method dispose
, which has two purposes:
dispose
.To ensure memory efficiency of applications, engineers should watch that:
Engineers want their applications to be memory efficient, but they want to minimize time and mental effort spent worrying about the items above.
leak_tracker fully automates item #1, and almost* fully automates item #2.
[!NOTE] *If a large set of objects is held from GC longer than needed, some of them are likely to be disposables, and thus leaks will be detected by the leak_tracker. This is not always true, though; in rare cases, a large set of objects is held from GC, but the set does not contain any disposables tracked by leak_tracker.
As a result, leak_tracker
increases confidence and reduces engineering effort related to memory efficiency.
Item #3 is not covered by leak_tracker
. There are no known tools to automate it so far. All known methods are manual:
How large can a memory leak be when disposal is forgotten or when an object is referenced after disposal?
The cases below are selected from the GitHub issue history and illustrate three types of memory issues:
dispose
Disposed but not GCed Route is leaking: https://github.com/flutter/flutter/issues/88073. (A route may reference the entire page widget tree.)
A Flutter customer building a large application found the application was leaking over 300KB at startup. Many of the leaked objects would be detected by this package.
dispose
Issues here are fixed by updating ‘dispose’, not invoking it. That means not invoked ‘dispose’ would cause a significant leak.
Vertices
causes app crash: https://github.com/flutter/flutter/issues/54762VideoPlayerController
causes leak 25MB: https://github.com/flutter/flutter/issues/86477AnimationController
causes significant leak: https://github.com/flutter/flutter/issues/84730ImageShader
causes significant leak: https://github.com/flutter/flutter/issues/82832GridView
causes crash: https://github.com/flutter/flutter/issues/19558CanvasImage
causes significant leak: https://github.com/flutter/flutter/issues/57746