-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Closed
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work lista: leak trackingIssues and PRs related to memory leaks detected by leak_trackerIssues and PRs related to memory leaks detected by leak_trackera: tests"flutter test", flutter_test, or one of our tests"flutter test", flutter_test, or one of our testsframeworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.team-frameworkOwned by Framework teamOwned by Framework teamtriaged-frameworkTriaged by Framework teamTriaged by Framework team
Description
Is there an existing issue for this?
- I have searched the existing issues
- I have read the guide to filing a bug
Steps to reproduce
_RenderSnapshotWidget does not dispose created OffsetLayer in _paintAndDetachToImage method when mode: SnapshotMode.permissive and PlatformView is in children.
Test to reveal the leak:
testWidgetsWithLeakTracking('Layers leak', (WidgetTester tester) async {
final SnapshotController controller = SnapshotController(allowSnapshotting: true);
addTearDown(controller.dispose);
await tester.pumpWidget(
Center(
child: TestDependencies(
child: SnapshotWidget(
controller: controller,
mode: SnapshotMode.permissive,
child: const SizedBox(
width: 100,
height: 100,
child: TestPlatformView(),
),
),
),
),
);
}, leakTrackingTestConfig: LeakTrackingTestConfig.debugNotDisposed());Test output
Layers leak
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: 2
objects:
PlatformViewLayer:
test: Layers leak
identityHashCode: 256926177
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:241:23)
#8______MemoryAllocations.dispatchObjectCreated_(package:flutter/src/foundation/memory_allocations.dart:275:5)
#9______new_Layer_(package:flutter/src/rendering/layer.dart:143:34)
#10_____new_PlatformViewLayer_(package:flutter/src/rendering/layer.dart)
#11_____RenderTestPlatformView.paint_(file:///Users/ksokolovskyi/dev/flutter_master/packages/flutter/test/widgets/snapshot_widget_test.dart:368:22)
#12_____RenderObject._paintWithContext_(package:flutter/src/rendering/object.dart:3208:7)
#13_____PaintingContext.paintChild_(package:flutter/src/rendering/object.dart:250:13)
#14_____RenderProxyBoxMixin.paint_(package:flutter/src/rendering/proxy_box.dart:129:13)
#15_____RenderObject._paintWithContext_(package:flutter/src/rendering/object.dart:3208:7)
#16_____PaintingContext.paintChild_(package:flutter/src/rendering/object.dart:250:13)
#17_____RenderProxyBoxMixin.paint_(package:flutter/src/rendering/proxy_box.dart:129:13)
#18______RenderSnapshotWidget._paintAndDetachToImage_(package:flutter/src/widgets/snapshot_widget.dart:302:11)
#19______RenderSnapshotWidget.paint_(package:flutter/src/widgets/snapshot_widget.dart:345:22)
#20_____RenderObject._paintWithContext_(package:flutter/src/rendering/object.dart:3208:7)
#21_____PaintingContext.paintChild_(package:flutter/src/rendering/object.dart:250:13)
#22_____RenderShiftedBox.paint_(package:flutter/src/rendering/shifted_box.dart:74:15)
#23_____RenderObject._paintWithContext_(package:flutter/src/rendering/object.dart:3208:7)
#24_____PaintingContext.paintChild_(package:flutter/src/rendering/object.dart:250:13)
#25_____RenderView.paint_(package:flutter/src/rendering/view.dart:223:15)
#26_____RenderObject._paintWithContext_(package:flutter/src/rendering/object.dart:3208:7)
#27_____PaintingContext._repaintCompositedChild_(package:flutter/src/rendering/object.dart:166:11)
#28_____PaintingContext.repaintCompositedChild_(package:flutter/src/rendering/object.dart:109:5)
#29_____PipelineOwner.flushPaint_(package:flutter/src/rendering/object.dart:1156:31)
#30_____PipelineOwner.flushPaint_(package:flutter/src/rendering/object.dart:1166:15)
#31_____AutomatedTestWidgetsFlutterBinding.drawFrame_(package:flutter_test/src/binding.dart:1415:31)
#32_____RendererBinding._handlePersistentFrameCallback_(package:flutter/src/rendering/binding.dart:457:5)
#33_____SchedulerBinding._invokeFrameCallback_(package:flutter/src/scheduler/binding.dart:1325:15)
#34_____SchedulerBinding.handleDrawFrame_(package:flutter/src/scheduler/binding.dart:1255:9)
#35_____AutomatedTestWidgetsFlutterBinding.pump.<anonymous_closure>_(package:flutter_test/src/binding.dart:1264:9)
#36______rootRun_(dart:async/zone.dart:1399:13)
#37______CustomZone.run_(dart:async/zone.dart:1301:19)
#38_____TestAsyncUtils.guard_(package:flutter_test/src/test_async_utils.dart:71:41)
#39_____AutomatedTestWidgetsFlutterBinding.pump_(package:flutter_test/src/binding.dart:1251:27)
#40_____WidgetTester.pumpWidget.<anonymous_closure>_(package:flutter_test/src/widget_tester.dart:578:22)
#41______rootRun_(dart:async/zone.dart:1399:13)
#42______CustomZone.run_(dart:async/zone.dart:1301:19)
#43_____TestAsyncUtils.guard_(package:flutter_test/src/test_async_utils.dart:71:41)
#44_____WidgetTester.pumpWidget_(package:flutter_test/src/widget_tester.dart:575:27)
#45_____main.<anonymous_closure>_(file:///Users/ksokolovskyi/dev/flutter_master/packages/flutter/test/widgets/snapshot_widget_test.dart:338:16)
#46_____testWidgetsWithLeakTracking.wrappedCallBack_(package:leak_tracker_flutter_testing/src/test_widgets.dart:126:19)
#47_____testWidgets.<anonymous_closure>.<anonymous_closure>_(package:flutter_test/src/widget_tester.dart:168:29)
<asynchronous_suspension>
#48_____TestWidgetsFlutterBinding._runTestBody_(package:flutter_test/src/binding.dart:1013:5)
<asynchronous_suspension>
#49_____StackZoneSpecification._registerCallback.<anonymous_closure>_(package:stack_trace/src/stack_zone_specification.dart:114:42)
<asynchronous_suspension>
OffsetLayer:
test: Layers leak
identityHashCode: 465185651
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:241:23)
#8______MemoryAllocations.dispatchObjectCreated_(package:flutter/src/foundation/memory_allocations.dart:275:5)
#9______new_Layer_(package:flutter/src/rendering/layer.dart:143:34)
#10_____new_ContainerLayer_(package:flutter/src/rendering/layer.dart)
#11_____new_OffsetLayer_(package:flutter/src/rendering/layer.dart)
#12______RenderSnapshotWidget._paintAndDetachToImage_(package:flutter/src/widgets/snapshot_widget.dart:300:37)
#13______RenderSnapshotWidget.paint_(package:flutter/src/widgets/snapshot_widget.dart:345:22)
#14_____RenderObject._paintWithContext_(package:flutter/src/rendering/object.dart:3208:7)
#15_____PaintingContext.paintChild_(package:flutter/src/rendering/object.dart:250:13)
#16_____RenderShiftedBox.paint_(package:flutter/src/rendering/shifted_box.dart:74:15)
#17_____RenderObject._paintWithContext_(package:flutter/src/rendering/object.dart:3208:7)
#18_____PaintingContext.paintChild_(package:flutter/src/rendering/object.dart:250:13)
#19_____RenderView.paint_(package:flutter/src/rendering/view.dart:223:15)
#20_____RenderObject._paintWithContext_(package:flutter/src/rendering/object.dart:3208:7)
#21_____PaintingContext._repaintCompositedChild_(package:flutter/src/rendering/object.dart:166:11)
#22_____PaintingContext.repaintCompositedChild_(package:flutter/src/rendering/object.dart:109:5)
#23_____PipelineOwner.flushPaint_(package:flutter/src/rendering/object.dart:1156:31)
#24_____PipelineOwner.flushPaint_(package:flutter/src/rendering/object.dart:1166:15)
#25_____AutomatedTestWidgetsFlutterBinding.drawFrame_(package:flutter_test/src/binding.dart:1415:31)
#26_____RendererBinding._handlePersistentFrameCallback_(package:flutter/src/rendering/binding.dart:457:5)
#27_____SchedulerBinding._invokeFrameCallback_(package:flutter/src/scheduler/binding.dart:1325:15)
#28_____SchedulerBinding.handleDrawFrame_(package:flutter/src/scheduler/binding.dart:1255:9)
#29_____AutomatedTestWidgetsFlutterBinding.pump.<anonymous_closure>_(package:flutter_test/src/binding.dart:1264:9)
#30______rootRun_(dart:async/zone.dart:1399:13)
#31______CustomZone.run_(dart:async/zone.dart:1301:19)
#32_____TestAsyncUtils.guard_(package:flutter_test/src/test_async_utils.dart:71:41)
#33_____AutomatedTestWidgetsFlutterBinding.pump_(package:flutter_test/src/binding.dart:1251:27)
#34_____WidgetTester.pumpWidget.<anonymous_closure>_(package:flutter_test/src/widget_tester.dart:578:22)
#35______rootRun_(dart:async/zone.dart:1399:13)
#36______CustomZone.run_(dart:async/zone.dart:1301:19)
#37_____TestAsyncUtils.guard_(package:flutter_test/src/test_async_utils.dart:71:41)
#38_____WidgetTester.pumpWidget_(package:flutter_test/src/widget_tester.dart:575:27)
#39_____main.<anonymous_closure>_(file:///Users/ksokolovskyi/dev/flutter_master/packages/flutter/test/widgets/snapshot_widget_test.dart:338:16)
#40_____testWidgetsWithLeakTracking.wrappedCallBack_(package:leak_tracker_flutter_testing/src/test_widgets.dart:126:19)
#41_____testWidgets.<anonymous_closure>.<anonymous_closure>_(package:flutter_test/src/widget_tester.dart:168:29)
<asynchronous_suspension>
#42_____TestWidgetsFlutterBinding._runTestBody_(package:flutter_test/src/binding.dart:1013:5)
<asynchronous_suspension>
#43_____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>As a working fix, we can add disposal of the created OffsetLayer as follows, but I don't know whether this is the right solution:
// Paint [child] with this painting context, then convert to a raster and detach all
// children from this layer.
ui.Image? _paintAndDetachToImage() {
final OffsetLayer offsetLayer = OffsetLayer();
final PaintingContext context = PaintingContext(offsetLayer, Offset.zero & size);
super.paint(context, Offset.zero);
// This ignore is here because this method is protected by the `PaintingContext`. Adding a new
// method that performs the work of `_paintAndDetachToImage` would avoid the need for this, but
// that would conflict with our goals of minimizing painting context.
// ignore: invalid_use_of_protected_member
context.stopRecordingIfNeeded();
if (mode != SnapshotMode.forced && !offsetLayer.supportsRasterization()) {
offsetLayer.dispose(); // <--- HERE!
if (mode == SnapshotMode.normal) {
throw FlutterError('SnapshotWidget used with a child that contains a PlatformView.');
}
_disableSnapshotAttempt = true;
return null;
}
final ui.Image image = offsetLayer.toImageSync(Offset.zero & size, pixelRatio: devicePixelRatio);
offsetLayer.dispose();
_lastCachedSize = size;
return image;
}Flutter Doctor output
Doctor output
[✓] Flutter (Channel master, 3.14.0-14.0.pre.377, on macOS 13.0.1 22A400 darwin-arm64, locale en-GB)
• Flutter version 3.14.0-14.0.pre.377 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 1e56af5a2e (7 hours ago), 2023-09-20 02:49:05 -0400
• Engine revision 24f7ac38df
• Dart version 3.2.0 (build 3.2.0-180.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!Metadata
Metadata
Assignees
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work lista: leak trackingIssues and PRs related to memory leaks detected by leak_trackerIssues and PRs related to memory leaks detected by leak_trackera: tests"flutter test", flutter_test, or one of our tests"flutter test", flutter_test, or one of our testsframeworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.team-frameworkOwned by Framework teamOwned by Framework teamtriaged-frameworkTriaged by Framework teamTriaged by Framework team