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: AnnotatedRegionLayer<SystemUiOverlayStyle> is not disposed when testing with _TestRecordingCanvasMatcher #134661

Closed
2 tasks done
ksokolovskyi opened this issue Sep 13, 2023 · 3 comments · Fixed by #136512
Labels
a: leak tracking Issues and PRs related to memory leaks detected by leak_tracker a: tests "flutter test", flutter_test, or one of our tests 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-framework Owned by Framework team triaged-framework Triaged by Framework team

Comments

@ksokolovskyi
Copy link
Contributor

ksokolovskyi commented Sep 13, 2023

Is there an existing issue for this?

PR which marks this leak: #134663

Steps to reproduce

It happens that AnnotatedRegionLayer<SystemUiOverlayStyle> is not disposed when testing with _TestRecordingCanvasMatcher.

  1. When running the following text with paintsExactlyCountTimes matcher leak_tracker detects leak:
testWidgetsWithLeakTracking('ListView should paint with offset', (WidgetTester tester) async {
  final ScrollController controller = ScrollController(initialScrollOffset: 120.0);
  addTearDown(controller.dispose);

  await tester.pumpWidget(
    MaterialApp(
      home: Scaffold(
        body: SizedBox(
          height: 500.0,
          child: CustomScrollView(
            controller: controller,
            slivers: <Widget>[
              const SliverAppBar(
                expandedHeight: 250.0,
              ),
              SliverList(
                delegate: ListView.builder(
                  itemExtent: 100.0,
                  itemCount: 100,
                  itemBuilder: (_, __) => const SizedBox(
                    height: 40.0,
                    child: Text('hey'),
                  ),
                ).childrenDelegate,
              ),
            ],
          ),
        ),
      ),
    ),
  );

  final RenderObject renderObject = tester.renderObject(find.byType(Scrollable));
  expect(renderObject, paintsExactlyCountTimes(#drawParagraph, 10));
}, leakTrackingTestConfig: LeakTrackingTestConfig.debugNotDisposed());
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:
                AnnotatedRegionLayer<SystemUiOverlayStyle>:
                  test: ListView should paint with offset
                  identityHashCode: 43646489
                  context:
                    start: >
                      #6_______flutterEventToLeakTracker_(package:leak_tracker_flutter_testing/src/test_widgets.dart:24:23)
                      #7______MemoryAllocations.dispatchObjectEvent_(package:flutter/src/foundation/memory_allocations.dart:238:23)
                      #8______MemoryAllocations.dispatchObjectCreated_(package:flutter/src/foundation/memory_allocations.dart:272:5)
                      #9______new_Layer_(package:flutter/src/rendering/layer.dart:143:34)
                      #10_____new_ContainerLayer_(package:flutter/src/rendering/layer.dart)
                      #11_____new_AnnotatedRegionLayer_(package:flutter/src/rendering/layer.dart)
                      #12_____RenderAnnotatedRegion.paint_(package:flutter/src/rendering/proxy_box.dart:5059:43)
                      #13_____TestRecordingPaintingContext.paintChild_(package:flutter_test/src/recording_canvas.dart:104:11)
                      #14_____RenderProxyBoxMixin.paint_(package:flutter/src/rendering/proxy_box.dart:129:13)
                      #15_____TestRecordingPaintingContext.paintChild_(package:flutter_test/src/recording_canvas.dart:104:11)
                      #16_____RenderSliverPersistentHeader.paint_(package:flutter/src/rendering/sliver_persistent_header.dart:311:15)
                      #17_____TestRecordingPaintingContext.paintChild_(package:flutter_test/src/recording_canvas.dart:104:11)
                      #18_____RenderViewportBase._paintContents_(package:flutter/src/rendering/viewport.dart:690:17)
                      #19_____TestRecordingPaintingContext.pushClipRect.<anonymous_closure>_(package:flutter_test/src/recording_canvas.dart:116:97)
                      #20_____ClipContext._clipAndPaint_(package:flutter/src/painting/clip.dart:25:12)
                      #21_____ClipContext.clipRectAndPaint_(package:flutter/src/painting/clip.dart:53:5)
                      #22_____TestRecordingPaintingContext.pushClipRect_(package:flutter_test/src/recording_canvas.dart:116:5)
                      #23_____RenderViewportBase.paint_(package:flutter/src/rendering/viewport.dart:665:38)
                      #24_____TestRecordingPaintingContext.paintChild_(package:flutter_test/src/recording_canvas.dart:104:11)
                      #25_____RenderProxyBoxMixin.paint_(package:flutter/src/rendering/proxy_box.dart:129:13)
                      #26_____TestRecordingPaintingContext.paintChild_(package:flutter_test/src/recording_canvas.dart:104:11)
                      #27_____RenderProxyBoxMixin.paint_(package:flutter/src/rendering/proxy_box.dart:129:13)
                      #28_____TestRecordingPaintingContext.paintChild_(package:flutter_test/src/recording_canvas.dart:104:11)
                      #29_____RenderProxyBoxMixin.paint_(package:flutter/src/rendering/proxy_box.dart:129:13)
                      #30_____TestRecordingPaintingContext.paintChild_(package:flutter_test/src/recording_canvas.dart:104:11)
                      #31_____RenderProxyBoxMixin.paint_(package:flutter/src/rendering/proxy_box.dart:129:13)
                      #32_____TestRecordingPaintingContext.paintChild_(package:flutter_test/src/recording_canvas.dart:104:11)
                      #33_____RenderProxyBoxMixin.paint_(package:flutter/src/rendering/proxy_box.dart:129:13)
                      #34_____TestRecordingPaintingContext.paintChild_(package:flutter_test/src/recording_canvas.dart:104:11)
                      #35_____RenderProxyBoxMixin.paint_(package:flutter/src/rendering/proxy_box.dart:129:13)
                      #36_____TestRecordingPaintingContext.paintChild_(package:flutter_test/src/recording_canvas.dart:104:11)
                      #37_____RenderProxyBoxMixin.paint_(package:flutter/src/rendering/proxy_box.dart:129:13)
                      #38_____RenderTransform.paint_(package:flutter/src/rendering/proxy_box.dart:2557:17)
                      #39_____TestRecordingPaintingContext.paintChild_(package:flutter_test/src/recording_canvas.dart:104:11)
                      #40_____RenderClipRect.paint_(package:flutter/src/rendering/proxy_box.dart:1552:17)
                      #41______evaluatePainter_(package:flutter_test/src/mock_canvas.dart:537:20)
                      #42______TestRecordingCanvasMatcher.matches_(package:flutter_test/src/mock_canvas.dart:554:12)
                      #43______expect_(package:matcher/src/expect/expect.dart:138:30)
                      #44_____expect_(package:matcher/src/expect/expect.dart:56:3)
                      #45_____expect_(package:flutter_test/src/widget_tester.dart:458:18)
                      #46_____main.<anonymous_closure>_(file:///Users/ksokolovskyi/dev/flutter_master/packages/flutter/test/widgets/list_view_viewporting_test.dart:508:5)
                      <asynchronous_suspension>
                      #47_____testWidgetsWithLeakTracking.wrappedCallBack_(package:leak_tracker_flutter_testing/src/test_widgets.dart:126:5)
                      <asynchronous_suspension>
                      #48_____testWidgets.<anonymous_closure>.<anonymous_closure>_(package:flutter_test/src/widget_tester.dart:168:15)
                      <asynchronous_suspension>
                      #49_____TestWidgetsFlutterBinding._runTestBody_(package:flutter_test/src/binding.dart:1013:5)
                      <asynchronous_suspension>
                      #50_____StackZoneSpecification._registerCallback.<anonymous_closure>_(package:stack_trace/src/stack_zone_specification.dart:114:42)
                      <asynchronous_suspension>
            
            
  
  package:matcher                                                  expect
  package:flutter_test/src/widget_tester.dart 458:18               expect
  package:leak_tracker_flutter_testing/src/test_widgets.dart 81:5  _tearDownTestingWithLeakTracking
  ===== asynchronous gap ===========================
  dart:async                                                       _CustomZone.registerBinaryCallback
  package:leak_tracker_flutter_testing/src/test_widgets.dart 59:9  configureLeakTrackingTearDown.<fn>
  
  1. When running the following text with commented paintsExactlyCountTimes matcher leak_tracker does not detect leak:
testWidgetsWithLeakTracking('ListView should paint with offset', (WidgetTester tester) async {
  final ScrollController controller = ScrollController(initialScrollOffset: 120.0);
  addTearDown(controller.dispose);

  await tester.pumpWidget(
    MaterialApp(
      home: Scaffold(
        body: SizedBox(
          height: 500.0,
          child: CustomScrollView(
            controller: controller,
            slivers: <Widget>[
              const SliverAppBar(
                expandedHeight: 250.0,
              ),
              SliverList(
                delegate: ListView.builder(
                  itemExtent: 100.0,
                  itemCount: 100,
                  itemBuilder: (_, __) => const SizedBox(
                    height: 40.0,
                    child: Text('hey'),
                  ),
                ).childrenDelegate,
              ),
            ],
          ),
        ),
      ),
    ),
  );

  // final RenderObject renderObject = tester.renderObject(find.byType(Scrollable));
  // expect(renderObject, paintsExactlyCountTimes(#drawParagraph, 10));
}, leakTrackingTestConfig: LeakTrackingTestConfig.debugNotDisposed());

Flutter Doctor output

Doctor output
[✓] Flutter (Channel master, 3.14.0-14.0.pre.270, on macOS 13.0.1 22A400 darwin-arm64, locale en-GB)
    • Flutter version 3.14.0-14.0.pre.270 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 622c2b2b07 (75 minutes ago), 2023-09-13 09:35:29 -0400
    • Engine revision 5e671d5c90
    • Dart version 3.2.0 (build 3.2.0-140.0.dev)
    • DevTools version 2.27.0

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
    • Android SDK at /Users/ksokolovskyi/Library/Android/sdk
    • Platform android-33, 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.1)
    • 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!
@ksokolovskyi
Copy link
Contributor Author

cc @polina-c

@huycozy
Copy link
Member

huycozy commented Sep 14, 2023

Thanks for the report. Reproduced the issue with the given sample test.

flutter doctor -v
[!] Flutter (Channel master, 3.14.0-14.0.pre.288, on macOS 13.5 22G74 darwin-x64, locale en-VN)
    • Flutter version 3.14.0-14.0.pre.288 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 ee9aef0130 (26 minutes ago), 2023-09-13 19:48:22 -0700
    • Engine revision cd90cc8469
    • Dart version 3.2.0 (build 3.2.0-140.0.dev)
    • DevTools version 2.27.0
    • 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.0)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.72.0

[✓] Connected device (3 available)
    • RMX2001 (mobile) • EUYTFEUSQSRGDA6D • android-arm64  • Android 11 (API 30)
    • macOS (desktop)  • macos            • darwin-x64     • macOS 13.5 22G74 darwin-x64
    • Chrome (web)     • chrome           • web-javascript • Google Chrome 116.0.5845.187

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

! Doctor found issues in 1 category.

@huycozy huycozy added a: tests "flutter test", flutter_test, or one of our tests framework flutter/packages/flutter repository. See also f: labels. has reproducible steps The issue has been confirmed reproducible and is ready to work on team-framework Owned by Framework team found in release: 3.14 Found to occur in 3.14 and removed in triage Presently being triaged by the triage team labels Sep 14, 2023
@goderbauer goderbauer added P2 Important issues not at the top of the work list triaged-framework Triaged by Framework team labels Sep 19, 2023
@polina-c polina-c added the a: leak tracking Issues and PRs related to memory leaks detected by leak_tracker label Sep 21, 2023
@huycozy huycozy added the r: fixed Issue is closed as already fixed in a newer version label Oct 16, 2023
@github-actions
Copy link

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 30, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
a: leak tracking Issues and PRs related to memory leaks detected by leak_tracker a: tests "flutter test", flutter_test, or one of our tests 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-framework Owned by Framework team triaged-framework Triaged by Framework team
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants