Skip to content

Memory Leak: _DefaultTabControllerState doesn't dispose created TabController. #136607

Closed

Description

@ksokolovskyi

Is there an existing issue for this?

Steps to reproduce

_DefaultTabControllerState does not dispose TabController after creating a new one with _copyWith.

Test to reveal the leak:

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';

void main() {
  testWidgetsWithLeakTracking(
    'DefaultTabController leak',
    (WidgetTester tester) async {
      final Key key = UniqueKey();

      Widget buildTabs(List<String> tabs) {
        return MaterialApp(
          home: Scaffold(
            body: DefaultTabController(
              key: key,
              length: tabs.length,
              child: TabBar(
                tabs: tabs.map<Widget>((String tab) => Tab(text: tab)).toList(),
              ),
            ),
          ),
        );
      }

      await tester.pumpWidget(buildTabs(<String>['A']));
      await tester.pump();
      await tester.pumpWidget(buildTabs(<String>['A', 'B']));
    },
  );
}
Test output
✓ DefaultTabController leak
Expected: leak free
  Actual: <Instance of 'Leaks'>
   Which: contains leaks:
          # The text is generated by leak_tracker.
          # For leak troubleshooting tips open:
          # https://github.com/dart-lang/leak_tracker/blob/main/doc/TROUBLESHOOT.md
          notDisposed:
            total: 1
            objects:
              TabController:
                test: DefaultTabController leak
                identityHashCode: 694584574
          
          

package:matcher                                                  expect
expect
widget_tester.dart:458
_tearDownTestingWithLeakTracking
test_widgets.dart:82
===== asynchronous gap ===========================
dart:async                                                       _CustomZone.registerBinaryCallback
configureLeakTrackingTearDown.<fn>
test_widgets.dart:59

Flutter Doctor output

Doctor output
[✓] Flutter (Channel master, 3.14.0-14.0.pre.842, on macOS 14.0 23A344 darwin-arm64, locale en-GB)
    • Flutter version 3.14.0-14.0.pre.842 on channel master at /Users/ksokolovskyi/dev/flutter_master
    • Upstream repository [email protected]:ksokolovskyi/flutter.git
    • FLUTTER_GIT_URL = [email protected]:ksokolovskyi/flutter.git
    • Framework revision b00216b320 (4 hours ago), 2023-10-15 10:25:12 -0400
    • Engine revision f8eb68b115
    • Dart version 3.3.0 (build 3.3.0-27.0.dev)
    • DevTools version 2.28.1

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
    • Android SDK at /Users/ksokolovskyi/Library/Android/sdk
    • Platform android-34, build-tools 33.0.1
    • ANDROID_HOME = /Users/ksokolovskyi/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.0)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15A240d
    • CocoaPods version 1.13.0

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2022.3)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231)

[✓] IntelliJ IDEA Community Edition (version 2023.2)
    • IntelliJ at /Applications/IntelliJ IDEA CE.app
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart

[✓] VS Code (version 1.83.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.74.0

[✓] Connected device (2 available)
    • macOS (desktop) • macos  • darwin-arm64   • macOS 14.0 23A344 darwin-arm64
    • Chrome (web)    • chrome • web-javascript • Google Chrome 117.0.5938.149

[✓] Network resources
    • All expected network resources are available.

• No issues found!

Activity

  1. added
    in triagePresently being triaged by the triage team
    on Oct 16, 2023
  2. huycozy commented on Oct 16, 2023

    @huycozy
    Member

    Reproduced this issue on the latest master channel.

    flutter doctor -v
    [!] Flutter (Channel master, 3.16.0-11.0.pre.67, on macOS 14.0 23A344 darwin-x64, locale en-VN)
        • Flutter version 3.16.0-11.0.pre.67 on channel master at /Users/huynq/Documents/GitHub/flutter_master
        ! Warning: `flutter` on your path resolves to /Users/huynq/Documents/GitHub/flutter/bin/flutter, which is not inside your current Flutter SDK checkout at /Users/huynq/Documents/GitHub/flutter_master. Consider adding /Users/huynq/Documents/GitHub/flutter_master/bin to the front of your path.
        ! Warning: `dart` on your path resolves to /Users/huynq/Documents/GitHub/flutter/bin/dart, which is not inside your current Flutter SDK checkout at /Users/huynq/Documents/GitHub/flutter_master. Consider adding /Users/huynq/Documents/GitHub/flutter_master/bin to the front of your path.
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision 4ea0d7d4de (4 hours ago), 2023-10-15 19:39:36 -0400
        • Engine revision 72598229be
        • Dart version 3.3.0 (build 3.3.0-27.0.dev)
        • DevTools version 2.28.1
        • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades.
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 32.0.0)
        • Android SDK at /Users/huynq/Library/Android/sdk
        • Platform android-34, build-tools 32.0.0
        • ANDROID_HOME = /Users/huynq/Library/Android/sdk
        • Java binary at: /Applications/Android Studio Giraffe.app/Contents/jbr/Contents/Home/bin/java
        • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 15.0)
        • Xcode at /Applications/Xcode.app/Contents/Developer
        • Build 15A240d
        • CocoaPods version 1.13.0
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Android Studio (version 2022.3)
        • Android Studio at /Applications/Android Studio Giraffe.app/Contents
        • Flutter plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/9212-flutter
        • Dart plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/6351-dart
        • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231)
    
    [✓] Android Studio (version 2022.2)
        • Android Studio at /Applications/Android Studio.app/Contents
        • Flutter plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/9212-flutter
        • Dart plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/6351-dart
        • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)
    
    [✓] VS Code (version 1.83.0)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.74.0
    
    [✓] Connected device (3 available)
        • RMX2001 (mobile) • EUYTFEUSQSRGDA6D • android-arm64  • Android 11 (API 30)
        • macOS (desktop)  • macos            • darwin-x64     • macOS 14.0 23A344 darwin-x64
        • Chrome (web)     • chrome           • web-javascript • Google Chrome 118.0.5993.70
    
    [✓] Network resources
        • All expected network resources are available.
    
    ! Doctor found issues in 1 category.
  3. added
    a: tests"flutter test", flutter_test, or one of our tests
    frameworkflutter/packages/flutter repository. See also f: labels.
    p: material_uimaterial_ui package in flutter/packages
    has reproducible stepsThe issue has been confirmed reproducible and is ready to work on
    team-designOwned by Design Languages team
    a: leak trackingIssues and PRs related to memory leaks detected by leak_tracker
    and removed
    in triagePresently being triaged by the triage team
    on Oct 16, 2023
  4. added
    P2Important issues not at the top of the work list
    triaged-designTriaged by Design Languages team
    on Oct 18, 2023
  5. added
    r: fixedIssue is closed as already fixed in a newer version
    on Oct 20, 2023
  6. github-actions commented on Nov 3, 2023

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  7. locked as resolved and limited conversation to collaborators on Nov 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work lista: leak trackingIssues and PRs related to memory leaks detected by leak_trackera: tests"flutter test", flutter_test, or one of our testsfound in release: 3.13Found to occur in 3.13found in release: 3.16Found to occur in 3.16frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onp: material_uimaterial_ui package in flutter/packagesr: fixedIssue is closed as already fixed in a newer versionteam-designOwned by Design Languages teamtriaged-designTriaged by Design Languages team

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions