Skip to content

Clean up memory leaks in Flutter Framework, phase 2. #137311

@polina-c

Description

@polina-c

Looking for volunteers to help with this!!! 🚀

Issues: all, open.
PRs: all, open.

Focus areas:
@polina-c: kick off cleanup for notGCed and integration with testWidgets

Bigger issue: #134787

Goal of this issue

  1. All disposables in FlutterFramework (listed below) should be instrumented for leak tracking (example).
  2. There should not be .withIgnored( under flutter/test (or .withIgnored( should have a comment that explains why the ignored leaks are ok).

How to turn on leak tracking?

Leak tracking is now off by default for Flutter Framework.
To turn it on, follow the instruction.
To check your changes for leaks, temporarily turn on leak tracking, then, to merge your change, turn it off.

This PR is regularly refreshed and runs bots with leak tracking on, to verify current status of flutter master: #138581.

Steps

The goal should be achieved by iteratively instrumenting the objects and removing them from ignore lists:

  1. Identify area that you plan to work on and comment on this issue so that I add you to the focus areas above so that we do not duplicate work. If your plans changed, also let me know.

  2. Instrument a new class:
    a. Create PR with instrumentation for one more object, mark it as draft, and check if bots pass
    a. If all bots pass, merge PR
    b. If number of failures is small and they are easy to fix, fix them in the same PR
    c. If failures are massive or unclear, add withIgnored( for the instrumented class either in root folder, or in sub-folder, or in a test file (in setUpAll), or for individual tests.

  3. Remove ignored leaks
    a. Identify withIgnored on any level (flutter_test_config.dart, test library or individual test), create draft PR with removed ignored leak types or classes and check if bots pass
    b. If bots pass remove all inclusions (withTracked) for this class/leak-type in subsets of tests and merge the PR
    c. If bots fail, return the withIgnored, and add withTracked for the leak to one of the failed tests
    d. Check the list of issues/PRs for work in progress for the failure.
    e. If you know how to fix the leak, fix it and merge the PR (example)
    f. If the fix is unclear, removewithTracked, create an issue, link the issue in TODO for the test, and merge the PR

  4. While testWidgets is not integrated with leak tracking, convert testWidgets to testWidgetsWithLeakTracking as instructed in phase 1

Templates

Template for steps to repro for leak issues:

  1. Locate the test: <perm link to the test>
  2. (Either) Add parameter leakTesting = LeakTesting.settings.withTracked(classes: ['TheClass'])
  3. (Or) Remove parameter leakTesting = LeakTesting.settings.withIgnored(...)
  4. See the test failing

Template for TODO:

TODO(<your alias>): fix the leak and remove ignore (or add tracking for <name of class>)
<link to the issue>

Note: your alias in TODO does not mean your obligation to fix the issue, it just indicates you have some knowledge about it.

Classes to instrument

Instrumentation for test-only classes is not a goal, but if it is needed to catch other leaks, feel free to instrument them.

  • _RouteEntry
  • AnimationController
  • AnimationEagerListenerMixin
  • BannerPainter
  • ChangeNotifier
  • CurvedAnimation
  • DisposableBuildContext
  • Element
  • GestureRecognizer
  • Image
  • ImageInfo
  • ImageStreamCompleterHandle
  • Layer
  • MultiDragPointerState
  • OverlayEntry
  • PerformanceModeRequestHandle
  • Picture
  • PipelineOwner
  • RenderObject
  • RestorationBucket
  • Route
  • ScrollDragController
  • SelectionOverlay
  • SemanticOwner
  • SnapshotPainter
  • State
  • TextPainter
  • TextSelectionOverlay

(Let me know if I missed something)

Metadata

Metadata

Assignees

Labels

P1High-priority issues at the top of the work lista: leak trackingIssues and PRs related to memory leaks detected by leak_trackerc: new featureNothing broken; request for a new capabilityframeworkflutter/packages/flutter repository. See also f: labels.r: duplicateIssue is closed as a duplicate of an existing issueteam-frameworkOwned by Framework team

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions