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

Investigation for leak in 'DecoratedBox handles loading images' #148862

Closed
wants to merge 5 commits into from

Conversation

polina-c
Copy link
Contributor

@polina-c polina-c commented May 22, 2024

Contributes to #145599

To repro run on this PR:

flutter test test/widgets/box_decoration_test.dart --dart-define LEAK_TRACKING=true

When added addTearDown(imageCache.clear); to the test, the exception happens:

The following StateError was thrown by an image listener:
Bad state: Cannot clone a disposed image.
The clone() method of a previously-disposed Image was called. Once an Image object has been
disposed, it can no longer be used to create handles, as the underlying data may have been released.

When the exception was thrown, this was the stack:
#0      Image.clone (dart:ui/painting.dart:1903:7)
#1      ImageInfo.clone (package:flutter/src/painting/image_stream.dart:65:20)
#2      ImageStreamCompleter.setImage (package:flutter/src/painting/image_stream.dart:747:32)
#12     FakeAsync.flushMicrotasks (package:fake_async/fake_async.dart:197:32)
#13     FakeAsync._fireTimersWhile (package:fake_async/fake_async.dart:236:5)
#14     FakeAsync.elapse (package:fake_async/fake_async.dart:141:5)
#15     AutomatedTestWidgetsFlutterBinding.idle (package:flutter_test/src/binding.dart:1389:24)
#16     WidgetTester.idle.<anonymous closure> (package:flutter_test/src/widget_tester.dart:1014:53)
#19     TestAsyncUtils.guard (package:flutter_test/src/test_async_utils.dart:71:41)
#20     WidgetTester.idle (package:flutter_test/src/widget_tester.dart:1014:27)
#21     main.<anonymous closure> (file:///Users/polinach/_/flutter_dev/packages/flutter/test/widgets/box_decoration_test.dart:92:18)
<asynchronous suspension>
#22     testWidgets.<anonymous closure>.<anonymous closure> (package:flutter_test/src/widget_tester.dart:183:15)
<asynchronous suspension>
#23     TestWidgetsFlutterBinding._runTestBody (package:flutter_test/src/binding.dart:1025:5)

@github-actions github-actions bot added the framework flutter/packages/flutter repository. See also f: labels. label May 22, 2024
@polina-c
Copy link
Contributor Author

polina-c commented May 22, 2024

Without imageCache.clear there are leaks. Here is creation call stack for the leaking image and completer:

ImageStreamCompleterHandle:
                      ...
                      #9______new_ImageStreamCompleterHandle.__(package:flutter/src/painting/image_stream.dart:465:41)
                      #10_____ImageStreamCompleter.keepAlive_(package:flutter/src/painting/image_stream.dart:655:39)
                      #11_____new__CachedImageBase_(package:flutter/src/painting/image_cache.dart:609:27)
                      #12_____new__CachedImage_(package:flutter/src/painting/image_cache.dart)
                      #13_____ImageCache.putIfAbsent.listener_(package:flutter/src/painting/image_cache.dart:414:34)
                      #14_____ImageStreamCompleter.setImage_(package:flutter/src/painting/image_stream.dart:747:25)
                      #15_____StackZoneSpecification._registerUnaryCallback.<anonymous_closure>.<anonymous_closure>_(package:stack_trace/src/stack_zone_specification.dart:127:36)
                      #16_____StackZoneSpecification._run_(package:stack_trace/src/stack_zone_specification.dart:207:15)
                      #17_____StackZoneSpecification._registerUnaryCallback.<anonymous_closure>_(package:stack_trace/src/stack_zone_specification.dart:127:24)
                      #18______rootRunUnary_(dart:async/zone.dart:1407:47)
                      #19______CustomZone.runUnary_(dart:async/zone.dart:1308:19)
                      #20_____Future._propagateToListeners.handleValueCallback_(dart:async/future_impl.dart:861:45)
                      #21_____Future._propagateToListeners_(dart:async/future_impl.dart:890:13)
                      #22_____Future._completeWithValue_(dart:async/future_impl.dart:666:5)
                      #23_____Future._asyncCompleteWithValue.<anonymous_closure>_(dart:async/future_impl.dart:736:7)
                      #24_____FakeAsync.flushMicrotasks_(package:fake_async/fake_async.dart:197:32)
                      #25_____FakeAsync._fireTimersWhile_(package:fake_async/fake_async.dart:236:5)
                      #26_____FakeAsync.elapse_(package:fake_async/fake_async.dart:141:5)
                      #27_____AutomatedTestWidgetsFlutterBinding.idle_(package:flutter_test/src/binding.dart:1389:24)
                      #28_____WidgetTester.idle.<anonymous_closure>_(package:flutter_test/src/widget_tester.dart:1014:53)
                      #29______rootRun_(dart:async/zone.dart:1399:13)
                      #30______CustomZone.run_(dart:async/zone.dart:1301:19)
                      #31_____TestAsyncUtils.guard_(package:flutter_test/src/test_async_utils.dart:71:41)
                      #32_____WidgetTester.idle_(package:flutter_test/src/widget_tester.dart:1014:27)
                      #33_____main.<anonymous_closure>_(file:///Users/polinach/_/flutter_dev/packages/flutter/test/widgets/box_decoration_test.dart:60:18)
                      <asynchronous_suspension>
                      #34_____testWidgets.<anonymous_closure>.<anonymous_closure>_(package:flutter_test/src/widget_tester.dart:183:15)
                      <asynchronous_suspension>
                      #35_____TestWidgetsFlutterBinding._runTestBody_(package:flutter_test/src/binding.dart:1025:5)
                      <asynchronous_suspension>
                      #36_____StackZoneSpecification._registerCallback.<anonymous_closure>_(package:stack_trace/src/stack_zone_specification.dart:114:42)
                      <asynchronous_suspension>

                _CachedImage:
                     ...
                      #9______new__CachedImageBase_(package:flutter/src/painting/image_cache.dart:613:41)
                      #10_____new__CachedImage_(package:flutter/src/painting/image_cache.dart)
                      #11_____ImageCache.putIfAbsent.listener_(package:flutter/src/painting/image_cache.dart:414:34)
                      #12_____ImageStreamCompleter.setImage_(package:flutter/src/painting/image_stream.dart:747:25)
                      #13_____StackZoneSpecification._registerUnaryCallback.<anonymous_closure>.<anonymous_closure>_(package:stack_trace/src/stack_zone_specification.dart:127:36)
                      #14_____StackZoneSpecification._run_(package:stack_trace/src/stack_zone_specification.dart:207:15)
                      #15_____StackZoneSpecification._registerUnaryCallback.<anonymous_closure>_(package:stack_trace/src/stack_zone_specification.dart:127:24)
                      #16______rootRunUnary_(dart:async/zone.dart:1407:47)
                      #17______CustomZone.runUnary_(dart:async/zone.dart:1308:19)
                      #18_____Future._propagateToListeners.handleValueCallback_(dart:async/future_impl.dart:861:45)
                      #19_____Future._propagateToListeners_(dart:async/future_impl.dart:890:13)
                      #20_____Future._completeWithValue_(dart:async/future_impl.dart:666:5)
                      #21_____Future._asyncCompleteWithValue.<anonymous_closure>_(dart:async/future_impl.dart:736:7)
                      #22_____FakeAsync.flushMicrotasks_(package:fake_async/fake_async.dart:197:32)
                      #23_____FakeAsync._fireTimersWhile_(package:fake_async/fake_async.dart:236:5)
                      #24_____FakeAsync.elapse_(package:fake_async/fake_async.dart:141:5)
                      #25_____AutomatedTestWidgetsFlutterBinding.idle_(package:flutter_test/src/binding.dart:1389:24)
                      #26_____WidgetTester.idle.<anonymous_closure>_(package:flutter_test/src/widget_tester.dart:1014:53)
                      #27______rootRun_(dart:async/zone.dart:1399:13)
                      #28______CustomZone.run_(dart:async/zone.dart:1301:19)
                      #29_____TestAsyncUtils.guard_(package:flutter_test/src/test_async_utils.dart:71:41)
                      #30_____WidgetTester.idle_(package:flutter_test/src/widget_tester.dart:1014:27)
                      #31_____main.<anonymous_closure>_(file:///Users/polinach/_/flutter_dev/packages/flutter/test/widgets/box_decoration_test.dart:60:18)
                      <asynchronous_suspension>
                      #32_____testWidgets.<anonymous_closure>.<anonymous_closure>_(package:flutter_test/src/widget_tester.dart:183:15)
                      <asynchronous_suspension>
                      #33_____TestWidgetsFlutterBinding._runTestBody_(package:flutter_test/src/binding.dart:1025:5)
                      <asynchronous_suspension>
                      #34_____StackZoneSpecification._registerCallback.<anonymous_closure>_(package:stack_trace/src/stack_zone_specification.dart:114:42)
                      <asynchronous_suspension>

@polina-c
Copy link
Contributor Author

@jonahwilliams, it seems it is a bug.
Cash clean up should not trigger usage after disposal, if clean up happens at the end of the test.
Can you help me to figure it out?

FYI: @goderbauer , @Piinks

@polina-c polina-c closed this Jun 7, 2024
@polina-c polina-c deleted the box-decoration-repro branch June 7, 2024 16:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
framework flutter/packages/flutter repository. See also f: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant