Skip to content

Memory leak detection with leak_tracker_flutter_testing #1975

Description

@kosratdev

Describe the bug
After adding the leak_tracker_flutter_testing dependency to the dev dependencies to detect memory leaks while running the tests. I found two memory leaks that happens multiple times in different tests. They are not disposed objects as listed below:

  • PanGestureRecognizer object in render_base_chart.dart file
  • TapGestureRecognizer object in render_base_chart.dart file
  • LongPressGestureRecognizer object in render_base_chart.dart file

The above memory leaks can be fixed easily just by disposing them in the detach method like below:

  @override
  void detach() {
    _validForMouseTracker = false;
    panGestureRecognizer.dispose();
    tapGestureRecognizer.dispose();
    longPressGestureRecognizer.dispose();
    super.detach();
  }

Furthermore, it has some other memory leaks, which are hard for me to fix as I'm not very familiar with the source code architecture.

  • TransformationController in axis_chart_scaffold_widget.dart file.
  • TransformationController in custom_interactive_viewer.dart file.

To Reproduce

  • Add leak_tracker_flutter_testing to the dev dependancies
dev_dependencies:
  ...
  leak_tracker_flutter_testing: any
  • Create flutter_test_config.dart file in the root of the test folder
import 'dart:async';

import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';

Future<void> testExecutable(FutureOr<void> Function() testMain) async {
  LeakTesting.enable();
  LeakTesting.settings = LeakTesting.settings
    .withIgnored(createdByTestHelpers: true);

  await testMain();
}
  • run tests to see detected memory leaks.

Screenshots
If applicable, add screenshots, or videoshots to help explain your problem.

Versions

  • Flutter Version: 3.35.1
  • FlChart Version: 1.0.0

I want to create a pull request to fix those memory leaks, but I can't fix the TransformationController leaks unless you help me.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions