Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory Leak: _SelectableTextState does not dispose _TextSpanEditingController #135046

Closed
2 tasks done
ksokolovskyi opened this issue Sep 19, 2023 · 3 comments · Fixed by #135049
Closed
2 tasks done

Memory Leak: _SelectableTextState does not dispose _TextSpanEditingController #135046

ksokolovskyi opened this issue Sep 19, 2023 · 3 comments · Fixed by #135049
Assignees
Labels
a: tests "flutter test", flutter_test, or one of our tests f: material design flutter/packages/flutter/material repository. found in release: 3.14 Found to occur in 3.14 framework flutter/packages/flutter repository. See also f: labels. has reproducible steps The issue has been confirmed reproducible and is ready to work on P2 Important issues not at the top of the work list r: fixed Issue is closed as already fixed in a newer version team-design Owned by Design Languages team triaged-design Triaged by Design Languages team

Comments

@ksokolovskyi
Copy link
Contributor

ksokolovskyi commented Sep 19, 2023

Is there an existing issue for this?

Steps to reproduce

When a new data or textSpan is passed into SelectableText, then _SelectableTextState creates a new _TextSpanEditingController and does not dispose the old one.

Test to reveal the leak:

testWidgetsWithLeakTracking('_SelectableTextState leak', (WidgetTester tester) async {
  await tester.pumpWidget(
    const MaterialApp(
      home: Material(
        child: SelectableText('A'),
      ),
    )
  );

  await tester.pumpWidget(
    const MaterialApp(
      home: Material(
        child: SelectableText('B'),
      ),
    )
  );
}, leakTrackingTestConfig: LeakTrackingTestConfig.debugNotDisposed());
Test output
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:
              _TextSpanEditingController:
                test: _SelectableTextState leak
                identityHashCode: 607982384
                context:
                  start: >
#6_______flutterEventToLeakTracker_
test_widgets.dart:24
#7______MemoryAllocations.dispatchObjectEvent_
memory_allocations.dart:238
#8______MemoryAllocations.dispatchObjectCreated_
memory_allocations.dart:272
#9______ChangeNotifier.maybeDispatchObjectCreation_
change_notifier.dart:234
#10_____new_ValueNotifier_
change_notifier.dart:538
#11_____new_TextEditingController_
editable_text.dart:198
#12_____new__TextSpanEditingController_
selectable_text.dart:34
#13______SelectableTextState.initState_
selectable_text.dart:530
#14_____StatefulElement._firstBuild_
framework.dart:5605
#15_____ComponentElement.mount_
framework.dart:5450
#16_____Element.inflateWidget_
framework.dart:4329
#17_____Element.updateChild_
framework.dart:3840
#18_____ComponentElement.performRebuild_
framework.dart:5499
#19_____Element.rebuild_
framework.dart:5190
#20_____ComponentElement._firstBuild_
framework.dart:5456
#21_____ComponentElement.mount_
framework.dart:5450
#22_____Element.inflateWidget_
framework.dart:4329
#23_____Element.updateChild_
framework.dart:3840
#24_____ComponentElement.performRebuild_
framework.dart:5499
#25_____StatefulElement.performRebuild_
framework.dart:5637
#26_____Element.rebuild_
framework.dart:5190
#27_____ComponentElement._firstBuild_
framework.dart:5456
#28_____StatefulElement._firstBuild_
framework.dart:5628
#29_____ComponentElement.mount_
framework.dart:5450
#30_____Element.inflateWidget_
framework.dart:432

Flutter Doctor output

Doctor output
[✓] Flutter (Channel master, 3.14.0-14.0.pre.358, on macOS 13.0.1 22A400 darwin-arm64, locale en-GB)
    • Flutter version 3.14.0-14.0.pre.358 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 8936504163 (12 hours ago), 2023-09-19 02:10:24 -0400
    • Engine revision 589bde9a95
    • Dart version 3.2.0 (build 3.2.0-174.0.dev)
    • DevTools version 2.28.0-dev.8

[✓] 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.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.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.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-arm64   • macOS 13.0.1 22A400 darwin-arm64
    • Chrome (web)    • chrome • web-javascript • Google Chrome 116.0.5845.187

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

• No issues found!
@huycozy huycozy added the in triage Presently being triaged by the triage team label Sep 20, 2023
@huycozy
Copy link
Member

huycozy commented Sep 20, 2023

Reproduced this with the given test. Thanks for the report and PR!

flutter doctor -v
[!] Flutter (Channel master, 3.14.0-14.0.pre.373, on macOS 13.5 22G74 darwin-x64, locale en-VN)
    • Flutter version 3.14.0-14.0.pre.373 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 f4b5fc1803 (73 minutes ago), 2023-09-19 22:43:57 -0400
    • Engine revision 5a924a9017
    • Dart version 3.2.0 (build 3.2.0-180.0.dev)
    • DevTools version 2.28.0-dev.8
    • 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.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.6 0-17.0.6b802.4-9586694)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.3)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14E222b
    • CocoaPods version 1.11.3

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

[✓] 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 (4 available)
    • RMX2001 (mobile) • EUYTFEUSQSRGDA6D                         • android-arm64  • Android 11 (API 30)
    • iPhone (mobile)  • d9a94afe2b649fef56ba0bfeb052f0f2a7dae95e • ios            • iOS 15.7.2 19H218
    • macOS (desktop)  • macos                                    • darwin-x64     • macOS 13.5 22G74 darwin-x64
    • Chrome (web)     • chrome                                   • web-javascript • Google Chrome 117.0.5938.62

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

! Doctor found issues in 1 category.

@huycozy huycozy added framework flutter/packages/flutter repository. See also f: labels. f: material design flutter/packages/flutter/material repository. has reproducible steps The issue has been confirmed reproducible and is ready to work on team-design Owned by Design Languages team found in release: 3.14 Found to occur in 3.14 a: tests "flutter test", flutter_test, or one of our tests and removed in triage Presently being triaged by the triage team labels Sep 20, 2023
@ksokolovskyi
Copy link
Contributor Author

cc @polina-c

@HansMuller HansMuller added P2 Important issues not at the top of the work list triaged-design Triaged by Design Languages team labels Sep 20, 2023
@huycozy huycozy added the r: fixed Issue is closed as already fixed in a newer version label Sep 21, 2023
@github-actions
Copy link

github-actions bot commented Oct 5, 2023

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 5, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
a: tests "flutter test", flutter_test, or one of our tests f: material design flutter/packages/flutter/material repository. found in release: 3.14 Found to occur in 3.14 framework flutter/packages/flutter repository. See also f: labels. has reproducible steps The issue has been confirmed reproducible and is ready to work on P2 Important issues not at the top of the work list r: fixed Issue is closed as already fixed in a newer version team-design Owned by Design Languages team triaged-design Triaged by Design Languages team
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants