Skip to content

Memory leak: TimePickerDialog does not dispose several ChangeNotifiers. #136260

@ksokolovskyi

Description

@ksokolovskyi

Is there an existing issue for this?

Steps to reproduce

TimePickerDialog does not dispose several ChangeNotifiers: RestorableValue, FocusNode and TextEditingController.

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(
    'TimePickerDialog leaks',
    (WidgetTester tester) async {
      await tester.pumpWidget(
        MaterialApp(
          home: Center(
            child: Builder(
              builder: (BuildContext context) {
                return TextButton(
                  onPressed: () {
                    showTimePicker(
                      context: context,
                      initialTime: const TimeOfDay(
                        hour: 3,
                        minute: 0,
                      ),
                      initialEntryMode: TimePickerEntryMode.input,
                    );
                  },
                  child: const Text('OPEN'),
                );
              },
            ),
          ),
        ),
      );

      await tester.tap(find.text('OPEN'));

      await tester.pumpAndSettle();
    },
  );
}
Test output
✓ TimePickerDialog leaks
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: 11
            objects:
              TextEditingController:
                test: TimePickerDialog leaks
                identityHashCode: 229692951
              FocusNode:
                test: TimePickerDialog leaks
                identityHashCode: 496108504
              RestorableBool:
                test: TimePickerDialog leaks
                identityHashCode: 26566488
              RestorableTextEditingController:
                test: TimePickerDialog leaks
                identityHashCode: 756700408
              TextEditingController:
                test: TimePickerDialog leaks
                identityHashCode: 352119660
              FocusNode:
                test: TimePickerDialog leaks
                identityHashCode: 317966576
              RestorableBool:
                test: TimePickerDialog leaks
                identityHashCode: 687899340
              RestorableTextEditingController:
                test: TimePickerDialog leaks
                identityHashCode: 462498029
              RestorableTimeOfDay:
                test: TimePickerDialog leaks
                identityHashCode: 999387979
              RestorableBool:
                test: TimePickerDialog leaks
                identityHashCode: 840403352
              RestorableBool:
                test: TimePickerDialog leaks
                identityHashCode: 934203956
          
          

package:matcher                                                  expect
expect
widget_tester.dart:458
_tearDownTestingWithLeakTracking
test_widgets.dart:82
===== asynchronous gap ===========================
dart:async                                                       _CustomZone.registerBinaryCallback

Flutter Doctor output

Doctor output
[✓] Flutter (Channel master, 3.14.0-14.0.pre.723, on macOS 13.0.1 22A400 darwin-arm64, locale en-GB)
    • Flutter version 3.14.0-14.0.pre.723 on channel master at /Users/ksokolovskyi/dev/flutter_master
    • Upstream repository git@github.com:ksokolovskyi/flutter.git
    • FLUTTER_GIT_URL = git@github.com:ksokolovskyi/flutter.git
    • Framework revision 7d01663885 (4 hours ago), 2023-10-10 07:21:27 -0400
    • Engine revision e354a13cfe
    • Dart version 3.3.0 (build 3.3.0-5.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 14.3.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14E300c
    • 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.0)
    • 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 13.0.1 22A400 darwin-arm64
    • Chrome (web)    • chrome • web-javascript • Google Chrome 117.0.5938.149

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

• No issues found!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions