Skip to content

ValueNotifier not disposed when dragging cupertino text field #135803

Closed

Description

@derdilla

Is there an existing issue for this?

Steps to reproduce

  1. remove notDisposedAllowList from the test Can double tap + drag to select word by word in test/cupertino/text_field_test.dart`.
  2. See test reporting one undisposed ValueNotifier<_OverlayEntryWidgetState?>

PR that adds leak tracking for said test: #135804

Expected results

The Cupertino text field should not leak.

Actual results

The test fails
notDisposed:
      total: 1
      objects:
          ValueNotifier<_OverlayEntryWidgetState?>:
               test: Can double tap + drag to select word by word
               identityHashCode: 823061609

Code sample

Other tests that would fail when converted with testWidgetsWithLeakTracking:

  • Can move cursor when dragging, when tap is on collapsed selection (iOS) - multiline
  • Can move cursor when dragging, when tap is on collapsed selection (iOS)
  • Can move cursor when dragging (Android)

This leads me to believe the issue is related to dragging on the text field.

Flutter Doctor output

Doctor output
[!] Flutter (Channel [user-branch], 3.14.0-14.0.pre.461, on Garuda Linux 6.5.4-zen2-1-zen, locale en_US.UTF-8)
    ! Flutter version 3.14.0-14.0.pre.461 on channel [user-branch] at /home/derdilla/Coding/Flutter/flutter/flutter/flutter
      Currently on an unknown channel. Run `flutter channel` to switch to an official channel.
      If that doesn't fix the issue, reinstall Flutter by following instructions at https://flutter.dev/docs/get-started/install.
    ! Upstream repository https://github.com/NobodyForNothing/flutter is not a standard remote.
      Set environment variable "FLUTTER_GIT_URL" to https://github.com/NobodyForNothing/flutter to dismiss this error.
    • Framework revision 2cc47574a9 (6 days ago), 2023-09-24 19:28:57 +0200
    • Engine revision e4bfdc1a67
    • Dart version 3.2.0 (build 3.2.0-190.0.dev)
    • DevTools version 2.28.0-dev.12
    • 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 34.0.0-rc3)
    • Android SDK at /home/derdilla/Android/Sdk
    • Platform android-34, build-tools 34.0.0-rc3
    • ANDROID_HOME = /home/derdilla/Android/Sdk
    • Java binary at: /home/derdilla/bin/apps/android-studio/jbr/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231)
    • All Android licenses accepted.

[✓] Chrome - develop for the web
    • CHROME_EXECUTABLE = /usr/bin/chromium

[✓] Linux toolchain - develop for Linux desktop
    • clang version 16.0.6
    • cmake version 3.27.6
    • ninja version 1.11.1
    • pkg-config version 1.8.1

[✓] Android Studio (version 2023.1)
    • Android Studio at /home/derdilla/bin/apps/android-studio
    • 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.3)
    • Android Studio at /home/derdilla/.local/share/JetBrains/Toolbox/apps/android-studio
    • 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 Ultimate Edition (version 2023.2)
    • IntelliJ at /home/derdilla/.local/share/JetBrains/Toolbox/apps/intellij-idea-ultimate
    • Flutter plugin version 75.1.4
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart

[✓] Connected device (2 available)
    • Linux (desktop) • linux  • linux-x64      • Garuda Linux 6.5.4-zen2-1-zen
    • Chrome (web)    • chrome • web-javascript • Chromium 117.0.5938.132 Arch Linux

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

! Doctor found issues in 1 category.

Activity

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

    @huycozy
    Member

    Hi @NobodyForNothing
    I can reproduce this on the latest stable but it seems to be fixed on master as the linked PR has been merged, right? If so, is this safe to close?

    flutter doctor -v (stable and master)
    [✓] Flutter (Channel stable, 3.13.6, on macOS 14.0 23A344 darwin-x64, locale en-VN)
        • Flutter version 3.13.6 on channel stable at /Users/huynq/Documents/GitHub/flutter
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision ead455963c (5 days ago), 2023-09-26 18:28:17 -0700
        • Engine revision a794cf2681
        • Dart version 3.1.3
        • DevTools version 2.25.0
    
    [✓] 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.11.3
    
    [✓] 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.82.2)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.72.0
    
    [✓] Connected device (2 available)
        • macOS (desktop) • macos  • darwin-x64     • macOS 14.0 23A344 darwin-x64
        • Chrome (web)    • chrome • web-javascript • Google Chrome 117.0.5938.132
    
    [✓] Network resources
        • All expected network resources are available.
    
    • No issues found!
    [!] Flutter (Channel master, 3.15.0-13.0.pre.40, on macOS 14.0 23A344 darwin-x64, locale en-VN)
        • Flutter version 3.15.0-13.0.pre.40 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 71acf24201 (3 hours ago), 2023-10-02 01:45:02 +0200
        • Engine revision 10b930ad1a
        • Dart version 3.2.0 (build 3.2.0-220.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.11.3
    
    [✓] 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.82.2)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.72.0
    
    [✓] Connected device (2 available)
        • macOS (desktop) • macos  • darwin-x64     • macOS 14.0 23A344 darwin-x64
        • Chrome (web)    • chrome • web-javascript • Google Chrome 117.0.5938.132
    
    [✓] Network resources
        • All expected network resources are available.
    
    ! Doctor found issues in 1 category.
  3. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Oct 2, 2023
  4. derdilla commented on Oct 2, 2023

    @derdilla
    ContributorAuthor

    The linked PR does not fix the issue. It only marks the leak, the issue still persists when you remove the notDisposedAllowlist.

    My reason for adding the allow list was to ensure no further leaks occur.

  5. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Oct 2, 2023
  6. huycozy commented on Oct 2, 2023

    @huycozy
    Member

    Could you share the modified test to reveal the leak? I ran the below test but can't reproduce it:

    Sample test
      testWidgetsWithLeakTracking(
        'Can double tap + drag to select word by word',
        (WidgetTester tester) async {
          final TextEditingController controller = TextEditingController();
    
          await tester.pumpWidget(
            CupertinoApp(
              home: CupertinoPageScaffold(
                child: CupertinoTextField(
                  dragStartBehavior: DragStartBehavior.down,
                  controller: controller,
                ),
              ),
            ),
          );
    
          const String testValue = 'abc def ghi';
          await tester.enterText(find.byType(CupertinoTextField), testValue);
          await tester.pumpAndSettle(const Duration(milliseconds: 200));
    
          final Offset ePos = textOffsetToPosition(tester, testValue.indexOf('e'));
          final Offset hPos = textOffsetToPosition(tester, testValue.indexOf('h'));
    
          // Tap on text field to gain focus, and set selection to '|e'.
          final TestGesture gesture = await tester.startGesture(ePos);
          await tester.pump();
          await gesture.up();
          await tester.pump();
    
          expect(controller.selection.isCollapsed, true);
          expect(controller.selection.baseOffset, testValue.indexOf('e'));
    
          // Here we tap on '|e' again, to register a double tap. This will select
          // the word at the tapped position.
          await gesture.down(ePos);
          await tester.pumpAndSettle();
    
          expect(controller.selection.baseOffset, 4);
          expect(controller.selection.extentOffset, 7);
    
          // Drag, right after the double tap, to select word by word.
          // Moving to the position of 'h', will extend the selection to 'ghi'.
          await gesture.moveTo(hPos);
          await tester.pumpAndSettle();
    
          // Toolbar should be hidden during a drag.
          expect(find.byType(CupertinoButton), findsNothing);
          expect(controller.selection.baseOffset, testValue.indexOf('d'));
          expect(controller.selection.extentOffset, testValue.indexOf('i') + 1);
    
          // Toolbar should re-appear after a drag.
          await gesture.up();
          await tester.pump();
          expect(find.byType(CupertinoButton), isContextMenuProvidedByPlatform ? findsNothing : findsNWidgets(4));
        },
    		leakTrackingTestConfig: LeakTrackingTestConfig.debugNotDisposed()
      );
  7. derdilla commented on Oct 2, 2023

    @derdilla
    ContributorAuthor
    Test code
    testWidgetsWithLeakTracking(
        'Can double tap + drag to select word by word',
        (WidgetTester tester) async {
          final TextEditingController controller = TextEditingController();
          addTearDown(controller.dispose);
    
          await tester.pumpWidget(
            CupertinoApp(
              home: CupertinoPageScaffold(
                child: CupertinoTextField(
                  dragStartBehavior: DragStartBehavior.down,
                  controller: controller,
                ),
              ),
            ),
          );
    
          const String testValue = 'abc def ghi';
          await tester.enterText(find.byType(CupertinoTextField), testValue);
          await tester.pumpAndSettle(const Duration(milliseconds: 200));
    
          final Offset ePos = textOffsetToPosition(tester, testValue.indexOf('e'));
          final Offset hPos = textOffsetToPosition(tester, testValue.indexOf('h'));
    
          // Tap on text field to gain focus, and set selection to '|e'.
          final TestGesture gesture = await tester.startGesture(ePos);
          await tester.pump();
          await gesture.up();
          await tester.pump();
    
          expect(controller.selection.isCollapsed, true);
          expect(controller.selection.baseOffset, testValue.indexOf('e'));
    
          // Here we tap on '|e' again, to register a double tap. This will select
          // the word at the tapped position.
          await gesture.down(ePos);
          await tester.pumpAndSettle();
    
          expect(controller.selection.baseOffset, 4);
          expect(controller.selection.extentOffset, 7);
    
          // Drag, right after the double tap, to select word by word.
          // Moving to the position of 'h', will extend the selection to 'ghi'.
          await gesture.moveTo(hPos);
          await tester.pumpAndSettle();
    
          // Toolbar should be hidden during a drag.
          expect(find.byType(CupertinoButton), findsNothing);
          expect(controller.selection.baseOffset, testValue.indexOf('d'));
          expect(controller.selection.extentOffset, testValue.indexOf('i') + 1);
    
          // Toolbar should re-appear after a drag.
          await gesture.up();
          await tester.pump();
          expect(find.byType(CupertinoButton), isContextMenuProvidedByPlatform ? findsNothing : findsNWidgets(4));
        },
        // TODO(derdilla): remove after fixing and leak track other failing tests in
        // this file. https://github.com/flutter/flutter/issues/135803
      );
  8. huycozy commented on Oct 2, 2023

    @huycozy
    Member

    Thanks but your given test is successful on the latest master channel (3.15.0-13.0.pre.40). Can you retry on master channel?

    ✓ Can double tap + drag to select word by word
    
  9. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Oct 2, 2023
  10. ksokolovskyi commented on Oct 2, 2023

    @ksokolovskyi
    Contributor

    Hi @huycozy.
    Please try to run the test from the terminal: flutter test 'test/cupertino/text_field_test.dart'.

  11. ksokolovskyi commented on Oct 2, 2023

    @ksokolovskyi
    Contributor

    @polina-c, do you know why running a test from IDE doesn't reveal the leak, but running from the terminal does?

    cupertino_text_field_test_leak.1.mp4
  12. added
    a: leak trackingIssues and PRs related to memory leaks detected by leak_tracker
    on Oct 2, 2023
  13. polina-c commented on Oct 2, 2023

    @polina-c
    Contributor

    Good question. Do you have latest version of flutter and latest version of leak_tracker?
    Try to run flutter -update-packages.
    I recently issued fix to make leak detection less flaky.

    Another thing: running from IDE may say the test passed, but then show failure for tearDownAll.
    Leak collection happens for all tests together in tearDownAll for performance goals.

  14. ksokolovskyi commented on Oct 3, 2023

    @ksokolovskyi
    Contributor

    Good question. Do you have latest version of flutter and latest version of leak_tracker? Try to run flutter -update-packages. I recently issued fix to make leak detection less flaky.

    Another thing: running from IDE may say the test passed, but then show failure for tearDownAll. Leak collection happens for all tests together in tearDownAll for performance goals.

    Yep, I have the latest version of the dependencies.
    Running all tests together from the IDE reveals the leak. But it is strange that IDE highlights the wrong test.

    leak_tracked_tests.mp4
  15. added
    r: fixedIssue is closed as already fixed in a newer version
    and removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    in triagePresently being triaged by the triage team
    on Oct 5, 2023
  16. droidbg commented on Oct 14, 2023

    @droidbg
    Contributor

    @polina-c I am also not able to see the leaks while running from android studio ide.

    Screen.Recording.2023-10-14.at.5.55.58.PM.mov
  17. polina-c commented on Oct 14, 2023

    @polina-c
    Contributor

    @ksokolovskyi , @droidbg

    Flakiness is a bad thing, because it means bots may eventually start failing for master branch, when tests are randomized in a certain way.
    To start working on the problem, we need repro steps that do not involve IDE, command line only.

    If we could find them, it would be reason to create a separate issue.

    For experiments you can use parameter --plain-name to run just one test.
    Or you can use parameter --test-randomize-ordering-seed=20230817, passing different dates.

  18. github-actions commented on Oct 28, 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.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    a: leak trackingIssues and PRs related to memory leaks detected by leak_trackerr: fixedIssue is closed as already fixed in a newer version

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions