Skip to content

Conversation

@gspencergoog
Copy link
Contributor

Description

Fix three memory leaks detected by about_test.dart, but were really in the Route and OverlayEntry classes.

Related Issues

Tests

  • Updates about_test.dart to not ignore the leaks anymore.

@gspencergoog gspencergoog requested a review from polina-c July 19, 2023 00:05
@github-actions github-actions bot added framework flutter/packages/flutter repository. See also f: labels. f: material design flutter/packages/flutter/material repository. f: routes Navigator, Router, and related APIs. labels Jul 19, 2023
polina-c
polina-c previously approved these changes Jul 19, 2023
@polina-c
Copy link
Contributor

@gspencergoog , can you check the fix is align with the recommendation: dart-lang/leak_tracker#97

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realized this is anti-pattern to release reference inside dispose. See the updated documentation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which part of the documentation? I don't see anything about this pattern.

What is the recommended solution then?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, the owner of the Route (which is really a subclass: MaterialPageRoute) is the Navigator, where it exists in a list of routes until it is popped and disposed. There's nothing to null out on the Navigator, since it's stored in a list.

@polina-c polina-c dismissed their stale review July 19, 2023 19:29

Found an issue. Let's make corrections.

@gspencergoog gspencergoog force-pushed the about_leak branch 2 times, most recently from 3d50210 to 0f52015 Compare July 20, 2023 16:45
@gspencergoog
Copy link
Contributor Author

@polina-c So, is this an OK solution now? The leak detector no longer shows a leak. If this solution is "hiding" the leak, then I'm not sure how to prevent the leak without nulling it out in dispose, and I'll need some guidance on how to do that.

@polina-c
Copy link
Contributor

polina-c commented Jul 21, 2023

@polina-c So, is this an OK solution now? The leak detector no longer shows a leak. If this solution is "hiding" the leak, then I'm not sure how to prevent the leak without nulling it out in dispose, and I'll need some guidance on how to do that.

How about removing nulling out for _restorationScopeId in disposal and see if leak still disappears? If it does not, I will help with investigation.

@gspencergoog
Copy link
Contributor Author

How about removing nulling out for _restorationScopeId in disposal and see if leak still disappears? If it does not, I will help with investigation.

Removing the nulling out of the _restorationScopeId in dispose still results in a leak.

Here are the logs:

Exception has occurred.
TestFailure (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
          notGCed:
            total: 1
            objects:
              ValueNotifier<String?>:
                identityHashCode: 76486441
                context:
                  start: >
                    #4_______withFlutterLeakTracking.flutterEventToLeakTracker_(file:///Users/gspencer/code/flutter/packages/flutter/test/foundation/leak_tracking.dart:112:12)
                    #5______MemoryAllocations.dispatchObjectEvent_(package:flutter/src/foundation/memory_allocations.dart:238:23)
                    #6______MemoryAllocations.dispatchObjectCreated_(package:flutter/src/foundation/memory_allocations.dart:272:5)
                    #7______new_ValueNotifier_(package:flutter/src/foundation/change_notifier.dart:508:34)
                    #8______new_Route_(package:flutter/src/widgets/navigator.dart:171:54)
                    #9______new_OverlayRoute_(package:flutter/src/widgets/routes.dart)
                    #10_____new_TransitionRoute_(package:flutter/src/widgets/routes.dart)
                    #11_____new__ModalRoute&TransitionRoute&LocalHistoryRoute_(package:flutter/src/widgets/routes.dart)
                    #12_____new_ModalRoute_(package:flutter/src/widgets/routes.dart)
                    #13_____new_PageRoute_(package:flutter/src/widgets/pages.dart)
                    #14_____new__MaterialPageRoute&PageRoute&MaterialRouteTransitionMixin_(package:flutter/src/material/page.dart)
                    #15_____new_MaterialPageRoute_(package:flutter/src/material/page.dart)
                    #16______MasterDetailFlowState._detailPageRoute_(package:flutter/src/material/about.dart:1230:12)
                    #17______MasterDetailFlowState._nestedUI.<anonymous_closure>_(package:flutter/src/material/about.dart:1204:22)
                    #18_____NavigatorState._routeNamed_(package:flutter/src/widgets/navigator.dart:4221:47)
                    #19_____NavigatorState.pushNamed_(package:flutter/src/widgets/navigator.dart:4280:21)
                    #20______MasterDetailFlowState.openDetailPage_(package:flutter/src/material/about.dart:1150:35)
                    #21______MasterDetailFlowProxy.openDetailPage_(package:flutter/src/material/about.dart:1115:19)
                    #22______PackagesViewState._packagesList.<anonymous_closure>.<anonymous_closure>_(package:flutter/src/material/about.dart:650:43)
                    #23______InkResponseState.handleTap_(package:flutter/src/material/ink_well.dart:1154:21)
                    #24_____GestureRecognizer.invokeCallback_(package:flutter/src/gestures/recognizer.dart:275:24)
                    #25_____TapGestureRecognizer.handleTapUp_(package:flutter/src/gestures/tap.dart:654:11)
                    #26_____BaseTapGestureRecognizer._checkUp_(package:flutter/src/gestures/tap.dart:311:5)
                    #27_____BaseTapGestureRecognizer.acceptGesture_(package:flutter/src/gestures/tap.dart:281:7)
                    #28_____GestureArenaManager.sweep_(package:flutter/src/gestures/arena.dart:167:27)
                    #29_____GestureBinding.handleEvent_(package:flutter/src/gestures/binding.dart:492:20)
                    #30_____GestureBinding.dispatchEvent_(package:flutter/src/gestures/binding.dart:468:22)
                    #31_____RendererBinding.dispatchEvent_(package:flutter/src/rendering/binding.dart:439:11)
                    #32_____GestureBinding._handlePointerEventImmediately_(package:flutter/src/gestures/binding.dart:413:7)
                    #33_____GestureBinding.handlePointerEvent_(package:flutter/src/gestures/binding.dart:376:5)
                    #34_____TestWidgetsFlutterBinding.handlePointerEventForSource.<anonymous_closure>_(package:flutter_test/src/binding.dart:652:42)
                    #35_____TestWidgetsFlutterBinding.withPointerEventSource_(package:flutter_test/src/binding.dart:662:11)
                    #36_____TestWidgetsFlutterBinding.handlePointerEventForSource_(package:flutter_test/src/binding.dart:652:5)
                    #37_____WidgetTester.sendEventToBinding.<anonymous_closure>_(package:flutter_test/src/widget_tester.dart:840:15)
                    #38______rootRun_(dart:async/zone.dart:1399:13)
                    #39______CustomZone.run_(dart:async/zone.dart:1301:19)
                    #40_____TestAsyncUtils.guard_(package:flutter_test/src/test_async_utils.dart:68:41)
                    #41_____WidgetTester.sendEventToBinding_(package:flutter_test/src/widget_tester.dart:839:27)
                    #42_____TestGesture.up.<anonymous_closure>_(package:flutter_test/src/test_pointer.dart:550:26)
                    #43______rootRun_(dart:async/zone.dart:1399:13)
                    #44______CustomZone.run_(dart:async/zone.dart:1301:19)
                    #45_____TestAsyncUtils.guard_(package:flutter_test/src/test_async_utils.dart:68:41)
                    #46_____TestGesture.up_(package:flutter_test/src/test_pointer.dart:543:27)
                    #47_____WidgetController.tapAt.<anonymous_closure>_(package:flutter_test/src/controller.dart:611:21)
                    <asynchronous_suspension>
                    #48_____TestAsyncUtils.guard.<anonymous_closure>_(package:flutter_test/src/test_async_utils.dart:114:7)
                    <asynchronous_suspension>
                    #49_____main.<anonymous_closure>_(file:///Users/gspencer/code/flutter/packages/flutter/test/material/about_test.dart:273:5)
                    <asynchronous_suspension>
                    #50_____withLeakTracking_(package:leak_tracker/src/leak_tracking/orchestration.dart:93:5)
                    <asynchronous_suspension>
                    #51______withFlutterLeakTracking.<anonymous_closure>_(file:///Users/gspencer/code/flutter/packages/flutter/test/foundation/leak_tracking.dart:120:21)
                    <asynchronous_suspension>
                    #52_____TestAsyncUtils.guard.<anonymous_closure>_(package:flutter_test/src/test_async_utils.dart:114:7)
                    <asynchronous_suspension>
                    #53_____testWidgetsWithLeakTracking.wrappedCallback_(file:///Users/gspencer/code/flutter/packages/flutter/test/foundation/leak_tracking.dart:60:5)
                    <asynchronous_suspension>
                    #54_____testWidgets.<anonymous_closure>.<anonymous_closure>_(package:flutter_test/src/widget_tester.dart:165:15)
                    <asynchronous_suspension>
                    #55_____TestWidgetsFlutterBinding._runTestBody_(package:flutter_test/src/binding.dart:1008:5)
                    <asynchronous_suspension>
                    #56_____StackZoneSpecification._registerCallback.<anonymous_closure>_(package:stack_trace/src/stack_zone_specification.dart:114:42)
                    <asynchronous_suspension>
                  disposal: >
                    #4_______withFlutterLeakTracking.flutterEventToLeakTracker_(file:///Users/gspencer/code/flutter/packages/flutter/test/foundation/leak_tracking.dart:112:12)
                    #5______MemoryAllocations.dispatchObjectEvent_(package:flutter/src/foundation/memory_allocations.dart:238:23)
                    #6______MemoryAllocations.dispatchObjectDisposed_(package:flutter/src/foundation/memory_allocations.dart:286:5)
                    #7______ChangeNotifier.dispose_(package:flutter/src/foundation/change_notifier.dart:357:34)
                    #8______Route.dispose_(package:flutter/src/widgets/navigator.dart:457:25)
                    #9______OverlayRoute.dispose_(package:flutter/src/widgets/routes.dart:91:11)
                    #10_____TransitionRoute.dispose_(package:flutter/src/widgets/routes.dart:489:11)
                    #11______RouteEntry.forcedDispose_(package:flutter/src/widgets/navigator.dart:3066:11)
                    #12______RouteEntry.dispose.<anonymous_closure>.<anonymous_closure>_(package:flutter/src/widgets/navigator.dart:3121:13)
                    #13_____StackZoneSpecification._run_(package:stack_trace/src/stack_zone_specification.dart:207:15)
                    #14_____StackZoneSpecification._registerCallback.<anonymous_closure>_(package:stack_trace/src/stack_zone_specification.dart:114:48)
                    #15______rootRun_(dart:async/zone.dart:1391:47)
                    #16______CustomZone.run_(dart:async/zone.dart:1301:19)
                    #17______CustomZone.runGuarded_(dart:async/zone.dart:1209:7)
                    #18______CustomZone.bindCallbackGuarded.<anonymous_closure>_(dart:async/zone.dart:1249:23)
                    #19_____FakeAsync.flushMicrotasks_(package:fake_async/fake_async.dart:197:32)
                    #20_____AutomatedTestWidgetsFlutterBinding.pump.<anonymous_closure>_(package:flutter_test/src/binding.dart:1261:26)
                    #21______rootRun_(dart:async/zone.dart:1399:13)
                    #22______CustomZone.run_(dart:async/zone.dart:1301:19)
                    #23_____TestAsyncUtils.guard_(package:flutter_test/src/test_async_utils.dart:68:41)
                    #24_____AutomatedTestWidgetsFlutterBinding.pump_(package:flutter_test/src/binding.dart:1246:27)
                    #25_____WidgetTester.pumpAndSettle.<anonymous_closure>_(package:flutter_test/src/widget_tester.dart:692:23)
                    <asynchronous_suspension>
                    #26_____TestAsyncUtils.guard.<anonymous_closure>_(package:flutter_test/src/test_async_utils.dart:114:7)
                    <asynchronous_suspension>
                    #27_____main.<anonymous_closure>_(file:///Users/gspencer/code/flutter/packages/flutter/test/material/about_test.dart:279:5)
                    <asynchronous_suspension>
                    #28_____withLeakTracking_(package:leak_tracker/src/leak_tracking/orchestration.dart:93:5)
                    <asynchronous_suspension>
                    #29______withFlutterLeakTracking.<anonymous_closure>_(file:///Users/gspencer/code/flutter/packages/flutter/test/foundation/leak_tracking.dart:120:21)
                    <asynchronous_suspension>
                    #30_____TestAsyncUtils.guard.<anonymous_closure>_(package:flutter_test/src/test_async_utils.dart:114:7)
                    <asynchronous_suspension>
                    #31_____testWidgetsWithLeakTracking.wrappedCallback_(file:///Users/gspencer/code/flutter/packages/flutter/test/foundation/leak_tracking.dart:60:5)
                    <asynchronous_suspension>
                    #32_____testWidgets.<anonymous_closure>.<anonymous_closure>_(package:flutter_test/src/widget_tester.dart:165:15)
                    <asynchronous_suspension>
                    #33_____TestWidgetsFlutterBinding._runTestBody_(package:flutter_test/src/binding.dart:1008:5)
                    <asynchronous_suspension>
                    #34_____StackZoneSpecification._registerCallback.<anonymous_closure>_(package:stack_trace/src/stack_zone_specification.dart:114:42)
                    <asynchronous_suspension>
                  path: >
                    References that retain the object from garbage collection.
                    package:flutter/src/widgets/app.dart/defaultActions
                    dart.collection/_Map:[InstanceRef id: classes/4650/types/0, kind: Type, identityHashCode: 3113980454, classRef: [ClassRef id: classes/48, name: _Type, library: [LibraryRef id: libraries/@0150898, name: dart.core, uri: dart:core]]]
                    package:flutter/src/widgets/actions.dart/VoidCallbackAction:_listeners@819441002
                    package:flutter/src/foundation/observer_list.dart/ObserverList:_list@441023516
                    dart.core/_GrowableList:0
                    dart.core/_Closure (in _handleActionChanged):_context@0150898
                    @Context:0
                    package:flutter/src/widgets/actions.dart/_ActionsState:listenedActions
                    dart.collection/_Set:data_
                    dart.core/_List:6
                    package:flutter/src/widgets/actions.dart/_OverridableContextAction:lookupContext
                    package:flutter/src/widgets/framework.dart/StatefulElement:_child@345042623
                    package:flutter/src/widgets/framework.dart/StatefulElement:_child@345042623
                    package:flutter/src/widgets/framework.dart/InheritedElement:_child@345042623
                    package:flutter/src/widgets/framework.dart/StatefulElement:_child@345042623
                    package:flutter/src/widgets/framework.dart/InheritedElement:_dependents@345042623
                    dart.collection/_HashMap:_buckets@3220832
                    dart.core/_List:5
                    dart.collection/_HashMapEntry:key
                    package:flutter/src/widgets/framework.dart/StatefulElement:_state@345042623
                    package:flutter/src/widgets/navigator.dart/NavigatorState:userGestureInProgressNotifier
                    package:flutter/src/foundation/change_notifier.dart/ValueNotifier:_listeners@429329750
                    dart.core/_List:0
                    dart.core/_Closure (in _handleChange):_context@0150898
                    @Context:0
                    package:flutter/src/widgets/transitions.dart/_AnimatedState:_element@345042623
                    package:flutter/src/widgets/framework.dart/StatefulElement:_child@345042623
                    package:flutter/src/widgets/framework.dart/SingleChildRenderObjectElement:_child@345042623
                    package:flutter/src/widgets/framework.dart/SingleChildRenderObjectElement:_child@345042623
                    package:flutter/src/widgets/framework.dart/StatelessElement:_child@345042623
                    package:flutter/src/widgets/framework.dart/SingleChildRenderObjectElement:_child@345042623
                    package:flutter/src/widgets/framework.dart/SingleChildRenderObjectElement:_child@345042623
                    package:flutter/src/widgets/framework.dart/StatefulElement:_state@345042623
                    package:flutter/src/material/about.dart/_LicensePageState:selectedId
                    package:flutter/src/foundation/change_notifier.dart/ValueNotifier:_listeners@429329750
                    dart.core/_List:0
                    dart.core/_Closure (in _valueChanged):_context@0150898
                    @Context:0
                    package:flutter/src/widgets/value_listenable_builder.dart/_ValueListenableBuilderState:_element@345042623
                    package:flutter/src/widgets/framework.dart/StatefulElement:_child@345042623
                    package:flutter/src/widgets/framework.dart/SingleChildRenderObjectElement:_child@345042623
                    package:flutter/src/widgets/framework.dart/StatefulElement:_state@345042623
                    package:flutter/src/material/material.dart/_MaterialState:_tickerModeNotifier@793311458
                    package:flutter/src/foundation/change_notifier.dart/ValueNotifier:_listeners@429329750
                    dart.core/_List:12
                    dart.core/_Closure (in _updateTicker):_context@0150898
                    @Context:0
                    package:flutter/src/widgets/implicit_animations.dart/_AnimatedDefaultTextStyleState:_element@345042623
                    package:flutter/src/widgets/framework.dart/StatefulElement:_child@345042623
                    package:flutter/src/widgets/framework.dart/InheritedElement:_child@345042623
                    package:flutter/src/widgets/framework.dart/StatelessElement:_child@345042623
                    package:flutter/src/widgets/framework.dart/MultiChildRenderObjectElement:_renderObject@345042623
                    package:flutter/src/rendering/paragraph.dart/RenderParagraph:_relayoutBoundary@360266271
                    package:flutter/src/rendering/viewport.dart/RenderViewport:_offset@743057554
                    package:flutter/src/widgets/scroll_position_with_single_context.dart/ScrollPositionWithSingleContext:context
                    package:flutter/src/widgets/scrollable.dart/ScrollableState:_element@345042623
                    package:flutter/src/widgets/framework.dart/StatefulElement:_child@345042623
                    package:flutter/src/widgets/framework.dart/StatefulElement:_state@345042623
                    package:flutter/src/widgets/overscroll_indicator.dart/_StretchingOverscrollIndicatorState:_stretchController@926442496
                    package:flutter/src/widgets/overscroll_indicator.dart/_StretchController:_listeners@429329750
                    dart.core/_List:0
                    dart.core/_Closure (in _handleChange):_context@0150898
                    @Context:0
                    package:flutter/src/widgets/transitions.dart/_AnimatedState:_element@345042623
                    package:flutter/src/widgets/framework.dart/StatefulElement:_child@345042623
                    package:flutter/src/widgets/framework.dart/SingleChildRenderObjectElement:_child@345042623
                    package:flutter/src/widgets/framework.dart/SingleChildRenderObjectElement:_child@345042623
                    package:flutter/src/widgets/notification_listener.dart/_NotificationElement:_child@345042623
                    package:flutter/src/widgets/framework.dart/SingleChildRenderObjectElement:_child@345042623
                    package:flutter/src/widgets/framework.dart/InheritedElement:_child@345042623
                    package:flutter/src/widgets/framework.dart/SingleChildRenderObjectElement:_child@345042623
                    package:flutter/src/widgets/framework.dart/StatefulElement:_child@345042623
                    package:flutter/src/widgets/framework.dart/SingleChildRenderObjectElement:_child@345042623
                    package:flutter/src/widgets/framework.dart/SingleChildRenderObjectElement:_child@345042623
                    package:flutter/src/widgets/framework.dart/SingleChildRenderObjectElement:_child@345042623
                    package:flutter/src/widgets/framework.dart/SingleChildRenderObjectElement:_child@345042623
                    package:flutter/src/widgets/viewport.dart/_ViewportElement:_children@345042623
                    dart.core/_List:0
                    package:flutter/src/widgets/framework.dart/SingleChildRenderObjectElement:_child@345042623
                    package:flutter/src/widgets/inherited_model.dart/InheritedModelElement:_dependents@345042623
                    dart.collection/_HashMap:_buckets@3220832
                    dart.core/_List:31
                    dart.collection/_HashMapEntry:next
                    dart.collection/_HashMapEntry:next
                    dart.collection/_HashMapEntry:key
                    package:flutter/src/widgets/framework.dart/StatelessElement:_child@345042623
                    package:flutter/src/widgets/framework.dart/StatelessElement:_child@345042623
                    package:flutter/src/widgets/framework.dart/SingleChildRenderObjectElement:_child@345042623
                    package:flutter/src/widgets/inherited_model.dart/InheritedModelElement:_dependents@345042623
                    dart.collection/_HashMap:_buckets@3220832
                    dart.core/_List:7
                    dart.collection/_HashMapEntry:key
                    package:flutter/src/widgets/framework.dart/StatelessElement:_child@345042623
                    package:flutter/src/widgets/framework.dart/MultiChildRenderObjectElement:_dependencies@345042623
                    dart.collection/_HashSet:_buckets@3220832
                    dart.core/_List:6
                    dart.collection/_HashSetEntry:key
                    package:flutter/src/widgets/basic.dart/_UbiquitousInheritedElement:_child@345042623
                    package:flutter/src/widgets/framework.dart/StatelessElement:_child@345042623
                    package:flutter/src/widgets/framework.dart/StatelessElement:_child@345042623
                    package:flutter/src/widgets/framework.dart/StatelessElement:_child@345042623
                    package:flutter/src/widgets/framework.dart/SingleChildRenderObjectElement:_child@345042623
                    package:flutter/src/widgets/framework.dart/InheritedElement:_child@345042623
                    package:flutter/src/widgets/framework.dart/StatelessElement:_child@345042623
                    package:flutter/src/widgets/framework.dart/StatefulElement:_state@345042623
                    package:flutter/src/material/scaffold.dart/ScaffoldMessengerState:_scaffolds@603420462
                    dart.collection/_Set:data_
                    dart.core/_List:2
                    package:flutter/src/material/scaffold.dart/ScaffoldState:_floatingActionButtonVisibilityController@603420462
                    package:flutter/src/animation/animation_controller.dart/AnimationController:_statusListeners@373091803
                    package:flutter/src/foundation/observer_list.dart/ObserverList:_list@441023516
                    dart.core/_GrowableList:2
                    dart.core/_Closure (in _maybeNotifyStatusListeners):_context@0150898
                    @Context:0
                    package:flutter/src/animation/animations.dart/AnimationMin:first
                    package:flutter/src/material/floating_action_button_location.dart/_AnimationSwap:_statusListeners@373091803
                    package:flutter/src/foundation/observer_list.dart/ObserverList:_list@441023516
                    dart.core/_GrowableList:1
                    dart.core/_Closure (in _maybeNotifyStatusListeners):_context@0150898
                    @Context:0
                    package:flutter/src/animation/animations.dart/AnimationMin:next
                    package:flutter/src/animation/animations.dart/CurvedAnimation:parent
                    package:flutter/src/animation/animation_controller.dart/AnimationController:_ticker@370066280
                    package:flutter/src/widgets/ticker_provider.dart/_WidgetTicker:_creator@793311458
                    package:flutter/src/material/scaffold.dart/_FloatingActionButtonTransitionState:_currentRotationAnimation@603420462
                    package:flutter/src/animation/animations.dart/TrainHoppingAnimation:_listeners@373091803
                    package:flutter/src/foundation/observer_list.dart/ObserverList:_list@441023516
                    dart.core/_GrowableList:0
                    dart.core/_Closure (in _handleChange):_context@0150898
                    @Context:0
                    package:flutter/src/widgets/transitions.dart/_AnimatedState:_element@345042623
                    package:flutter/src/widgets/framework.dart/StatefulElement:_child@345042623
                    package:flutter/src/widgets/framework.dart/SingleChildRenderObjectElement:_renderObject@345042623
                    package:flutter/src/rendering/proxy_box.dart/RenderTransform:_relayoutBoundary@360266271
                    package:flutter/src/rendering/custom_layout.dart/RenderCustomMultiChildLayoutBox:_lastChild@360266271
                    package:flutter/src/rendering/stack.dart/RenderStack:debugCreator
                    package:flutter/src/widgets/framework.dart/DebugCreator:element
                    package:flutter/src/widgets/framework.dart/MultiChildRenderObjectElement:_ancestorRenderObjectElement@345042623
                    package:flutter/src/widgets/framework.dart/MultiChildRenderObjectElement:_children@345042623
                    dart.core/_List:1
                    package:flutter/src/widgets/framework.dart/ParentDataElement:_child@345042623
                    package:flutter/src/widgets/inherited_model.dart/InheritedModelElement:_dependents@345042623
                    dart.collection/_HashMap:_buckets@3220832
                    dart.core/_List:3
                    dart.collection/_HashMapEntry:key
                    package:flutter/src/widgets/framework.dart/StatelessElement:_child@345042623
                    package:flutter/src/widgets/framework.dart/SingleChildRenderObjectElement:_child@345042623
                    package:flutter/src/widgets/inherited_model.dart/InheritedModelElement:_dependents@345042623
                    dart.collection/_HashMap:_buckets@3220832
                    dart.core/_List:1
                    dart.collection/_HashMapEntry:next
                    dart.collection/_HashMapEntry:key
                    package:flutter/src/widgets/framework.dart/StatefulElement:_state@345042623
                    package:flutter/src/material/ink_well.dart/_InkResponseState:_actionMap@561059085
                    dart.collection/_Map:[InstanceRef id: classes/4656/types/0, kind: Type, identityHashCode: 3491188443, classRef: [ClassRef id: classes/48, name: _Type, library: [LibraryRef id: libraries/@0150898, name: dart.core, uri: dart:core]]]
                    package:flutter/src/widgets/actions.dart/CallbackAction:_listeners@819441002
                    package:flutter/src/foundation/observer_list.dart/ObserverList:_list@441023516
                    dart.core/_GrowableList:0
                    dart.core/_Closure (in _handleActionChanged):_context@0150898
                    @Context:0
                    package:flutter/src/widgets/actions.dart/_ActionsState:_element@345042623
                    package:flutter/src/widgets/framework.dart/StatefulElement:_child@345042623
                    package:flutter/src/widgets/framework.dart/InheritedElement:_child@345042623
                    package:flutter/src/widgets/framework.dart/StatefulElement:_state@345042623
                    package:flutter/src/widgets/focus_scope.dart/_FocusState:_internalNode@834492240
                    package:flutter/src/widgets/focus_manager.dart/FocusNode:_parent@833042876
                    package:flutter/src/widgets/focus_manager.dart/FocusScopeNode:_parent@833042876
                    package:flutter/src/widgets/focus_manager.dart/FocusNode:_children@833042876
                    dart.core/_GrowableList:0
                    package:flutter/src/widgets/focus_manager.dart/FocusScopeNode:_children@833042876
                    dart.core/_GrowableList:1
                    package:flutter/src/widgets/focus_manager.dart/FocusNode:_ancestors@833042876
                    dart.core/_GrowableList:11
                    package:flutter/src/widgets/focus_manager.dart/FocusNode:_context@833042876
                    package:flutter/src/widgets/framework.dart/StatefulElement:_child@345042623
                    package:flutter/src/widgets/inherited_notifier.dart/_InheritedNotifierElement:_dependents@345042623
                    dart.collection/_HashMap:_buckets@3220832
                    dart.core/_List:6
                    dart.collection/_HashMapEntry:key
                    package:flutter/src/widgets/framework.dart/StatefulElement:_child@345042623
                    package:flutter/src/widgets/inherited_notifier.dart/_InheritedNotifierElement:_dependents@345042623
                    dart.collection/_HashMap:_buckets@3220832
                    dart.core/_List:0
                    dart.collection/_HashMapEntry:key
                    package:flutter/src/widgets/framework.dart/StatefulElement:_child@345042623
                    package:flutter/src/widgets/inherited_notifier.dart/_InheritedNotifierElement:_dependents@345042623
                    dart.collection/_HashMap:_buckets@3220832
                    dart.core/_List:0
                    dart.collection/_HashMapEntry:key
                    package:flutter/src/widgets/framework.dart/StatefulElement:_child@345042623
                    package:flutter/src/widgets/inherited_notifier.dart/_InheritedNotifierElement:_dependents@345042623
                    dart.collection/_HashMap:_buckets@3220832
                    dart.core/_List:3
                    dart.collection/_HashMapEntry:key
                    package:flutter/src/widgets/framework.dart/StatefulElement:_child@345042623
                    package:flutter/src/widgets/inherited_notifier.dart/_InheritedNotifierElement:_dependents@345042623
                    dart.collection/_HashMap:_buckets@3220832
                    dart.core/_List:4
                    dart.collection/_HashMapEntry:key
                    package:flutter/src/widgets/framework.dart/StatefulElement:_child@345042623
                    package:flutter/src/widgets/framework.dart/SingleChildRenderObjectElement:_renderObject@345042623
                    package:flutter/src/rendering/proxy_box.dart/RenderSemanticsAnnotations:_child@360266271
                    package:flutter/src/rendering/proxy_box.dart/RenderPointerListener:_child@360266271
                    package:flutter/src/rendering/proxy_box.dart/RenderAbsorbPointer:_child@360266271
                    package:flutter/src/widgets/overlay.dart/_RenderTheater:_lastChild@360266271
                    package:flutter/src/rendering/proxy_box.dart/RenderSemanticsAnnotations:_child@360266271
                    package:flutter/src/rendering/proxy_box.dart/RenderOffstage:_child@360266271
                    package:flutter/src/rendering/proxy_box.dart/RenderSemanticsAnnotations:_child@360266271
                    package:flutter/src/rendering/proxy_box.dart/RenderRepaintBoundary:_child@360266271
                    package:flutter/src/widgets/snapshot_widget.dart/_RenderSnapshotWidget:_painter@823188970
                    package:flutter/src/material/page_transitions_theme.dart/_ZoomEnterTransitionPainter:animation
                    package:flutter/src/animation/animations.dart/ProxyAnimation:_statusListeners@373091803
                    package:flutter/src/foundation/observer_list.dart/ObserverList:_list@441023516
                    dart.core/_GrowableList:0
                    dart.core/_Closure (in onAnimationStatusChange):_context@0150898
                    @Context:0
                    package:flutter/src/material/page_transitions_theme.dart/_ZoomEnterTransitionState:_element@345042623
                    package:flutter/src/widgets/framework.dart/StatefulElement:_child@345042623
                    package:flutter/src/widgets/framework.dart/SingleChildRenderObjectElement:_child@345042623
                    package:flutter/src/widgets/framework.dart/StatefulElement:_state@345042623
                    package:flutter/src/material/page_transitions_theme.dart/_ZoomExitTransitionState:delegate
                    package:flutter/src/material/page_transitions_theme.dart/_ZoomExitTransitionPainter:animation
                    package:flutter/src/animation/animations.dart/ProxyAnimation:_parent@371411118
                    package:flutter/src/animation/animations.dart/ReverseAnimation:parent
                    package:flutter/src/animation/animations.dart/ProxyAnimation:_parent@371411118
                    package:flutter/src/animation/animation_controller.dart/AnimationController:_statusListeners@373091803
                    package:flutter/src/foundation/observer_list.dart/ObserverList:_list@441023516
                    dart.core/_GrowableList:0
                    dart.core/_Closure (in _handleStatusChanged):_context@0150898
                    @Context:0
                    package:flutter/src/material/page.dart/MaterialPageRoute:_modalScope@799188637
                    package:flutter/src/widgets/overlay.dart/OverlayEntry:_overlay@863319124
                    package:flutter/src/widgets/overlay.dart/OverlayState:_element@345042623
                    package:flutter/src/widgets/framework.dart/StatefulElement:_child@345042623
                    package:flutter/src/widgets/overlay.dart/_TheaterElement:_children@345042623
                    dart.core/_List:1
                    package:flutter/src/widgets/framework.dart/StatefulElement:_child@345042623
                    package:flutter/src/widgets/framework.dart/StatefulElement:_state@345042623
                    package:flutter/src/widgets/ticker_provider.dart/_TickerModeState:_effectiveMode@793311458
                    package:flutter/src/foundation/change_notifier.dart/ValueNotifier:_listeners@429329750
                    dart.core/_List:0
                    dart.core/_Closure (in _updateTickers):_context@0150898
                    @Context:0
                    package:flutter/src/widgets/navigator.dart/NavigatorState:_history@31124995
                    dart.core/_GrowableList:0
                    package:flutter/src/widgets/navigator.dart/_RouteEntry:lastAnnouncedPoppedNextRoute
                    package:flutter/src/material/page.dart/MaterialPageRoute:_restorationScopeId@31124995
                    package:flutter/src/foundation/change_notifier.dart/ValueNotifier
          
          
)

@polina-c
Copy link
Contributor

Thanks!
This means reverence to MaterialPageRoute where the method dispose is located (see the tail of the retaining path), is never released. Can it be released?

@gspencergoog
Copy link
Contributor Author

This means reverence to MaterialPageRoute where the method dispose is located (see the tail of the retaining path), is never released. Can it be released?

The leak does indeed seem to involve _RouteEntry.lastAnnouncedPoppedNextRoute: when I remove that variable entirely (along with its functionality), the leak goes away.

I tried converting it to nullable and nulling it in _RouteEntry.dispose (really in _RouteEntry.forcedDispose, which is called from the dispose), but that doesn't prevent the leak. I also tried keeping it non-nullable and just setting it back to its initial value in dispose, which still leaked a MaterialPageRoute, which is not the type of the initial value. If I try and call dispose on the leaked object (lastAnnouncedPoppedNextRoute), then it leaks two instances of the ID instead of one, which is confusing to me.

Any other ideas?

@polina-c
Copy link
Contributor

polina-c commented Jul 21, 2023

_RouteEntry.lastAnnouncedPoppedNextRoute should be released before or at the same time with disposal of lastAnnouncedPoppedNextRoute, not parent's disposal.
It seems some other object (do we know which?) owns and disposes lastAnnouncedPoppedNextRoute.

Will it make sense for lastAnnouncedPoppedNextRoute to be converted to WeakRef, so that it can be garbage collected when it is not needed to other objects?

@gspencergoog
Copy link
Contributor Author

Will it make sense for lastAnnouncedPoppedNextRoute to be converted to WeakRef, so that it can be garbage collected when it is not needed to other objects?

Yes, I think that would make sense. If I read the code right, it doesn't really own the object, it's just using it to compare to a later result.

Converting it to a WeakReference<Route<dynamic>> indeed causes the leak to be fixed.

@gspencergoog gspencergoog force-pushed the about_leak branch 8 times, most recently from 64637ed to 14b3f4b Compare July 24, 2023 18:02
@github-actions github-actions bot added the f: gestures flutter/packages/flutter/gestures repository. label Jul 24, 2023
@gspencergoog gspencergoog added the autosubmit Merge PR when tree becomes green via auto submit App label Jul 24, 2023
@auto-submit
Copy link
Contributor

auto-submit bot commented Jul 25, 2023

auto label is removed for flutter/flutter, pr: 130842, due to - The status or check suite Google testing has failed. Please fix the issues identified (or deflake) before re-applying this label.

@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Jul 25, 2023
@sigmundch
Copy link
Contributor

That was exactly going to be my suggestion @jacob314

The flutter supported platforms doc indicates that our support starts from FF 99+. Internally some apps do support FF 85, so I think it would be fair to bump it at least to FF 85, but could be as far as FF 99.

In the past, due to issues with Geckodriver, our team did something similar and bumped from FF 63 to FF 72. At that point in time FF 72 was the min version supported for flutter web, which is why I think we are using 72 on those tests at the moment. See cl/456802232.

@polina-c
Copy link
Contributor

Thanks.
flutter/contrib/cached_network_image/BUILD is already at 114

Bumped hello_flutter: cl/551925539

@polina-c
Copy link
Contributor

CL got blocked by stacktrace parsing issue in Flutter: #131627

@polina-c
Copy link
Contributor

Issue for debug mode in Firefox: #132439

@gspencergoog gspencergoog force-pushed the about_leak branch 2 times, most recently from 17bec30 to 24e91c8 Compare August 15, 2023 19:02
@gspencergoog gspencergoog added the autosubmit Merge PR when tree becomes green via auto submit App label Aug 15, 2023
@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Aug 15, 2023
@auto-submit
Copy link
Contributor

auto-submit bot commented Aug 15, 2023

auto label is removed for flutter/flutter/130842, due to - The status or check suite docs-linux has failed. Please fix the issues identified (or deflake) before re-applying this label.

  • The status or check suite customer_testing-linux has failed. Please fix the issues identified (or deflake) before re-applying this label.
  • The status or check suite framework_tests-misc-linux has failed. Please fix the issues identified (or deflake) before re-applying this label.
  • The status or check suite framework_tests-widgets-linux has failed. Please fix the issues identified (or deflake) before re-applying this label.
  • The status or check suite framework_tests-libraries-linux has failed. Please fix the issues identified (or deflake) before re-applying this label.
  • The status or check suite analyze-linux has failed. Please fix the issues identified (or deflake) before re-applying this label.

@gspencergoog gspencergoog added the autosubmit Merge PR when tree becomes green via auto submit App label Aug 15, 2023
@auto-submit auto-submit bot merged commit 301577a into flutter:master Aug 15, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 16, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 16, 2023
auto-submit bot pushed a commit to flutter/packages that referenced this pull request Aug 16, 2023
flutter/flutter@f0e7c51...2502b51

2023-08-16 engine-flutter-autoroll@skia.org Roll Flutter Engine from f186f1e9dc88 to 70b5700b79f6 (1 revision) (flutter/flutter#132655)
2023-08-16 engine-flutter-autoroll@skia.org Roll Flutter Engine from e8670f03a9b1 to f186f1e9dc88 (2 revisions) (flutter/flutter#132649)
2023-08-16 whesse@google.com Fix flutter_tools use of --local-engine-host (flutter/flutter#132648)
2023-08-16 engine-flutter-autoroll@skia.org Roll Flutter Engine from 7cc6a5832a0e to e8670f03a9b1 (3 revisions) (flutter/flutter#132623)
2023-08-16 engine-flutter-autoroll@skia.org Roll Flutter Engine from decaccfc421d to 7cc6a5832a0e (1 revision) (flutter/flutter#132621)
2023-08-16 engine-flutter-autoroll@skia.org Roll Flutter Engine from 659cdfc5a568 to decaccfc421d (6 revisions) (flutter/flutter#132618)
2023-08-16 engine-flutter-autoroll@skia.org Roll Flutter Engine from 7409ce4ba0a8 to 659cdfc5a568 (1 revision) (flutter/flutter#132612)
2023-08-16 jonahwilliams@google.com Revert "Reorganize and clarify API doc generator" (flutter/flutter#132613)
2023-08-16 engine-flutter-autoroll@skia.org Roll Flutter Engine from a9da7212eacf to 7409ce4ba0a8 (5 revisions) (flutter/flutter#132609)
2023-08-16 engine-flutter-autoroll@skia.org Roll Flutter Engine from 22f03ffdc290 to a9da7212eacf (4 revisions) (flutter/flutter#132608)
2023-08-16 tessertaha@gmail.com [Reland] #131609 (flutter/flutter#132555)
2023-08-15 dkwingsmt@users.noreply.github.com Explain the keyboard manager protocol (flutter/flutter#132533)
2023-08-15 katelovett@google.com Fix extent for null returning builder in GridView (flutter/flutter#132511)
2023-08-15 gspencergoog@users.noreply.github.com Reorganize and clarify API doc generator (flutter/flutter#132353)
2023-08-15 gspencergoog@users.noreply.github.com Fixing a memory leak in About box/dialog overlays (flutter/flutter#130842)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC bmparr@google.com,rmistry@google.com,stuartmorgan@google.com on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://bugs.chromium.org/p/skia/issues/entry?template=Autoroller+Bug

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Nov 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autosubmit Merge PR when tree becomes green via auto submit App f: gestures flutter/packages/flutter/gestures repository. f: material design flutter/packages/flutter/material repository. f: routes Navigator, Router, and related APIs. framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

memory leak: widgets/app.dart/defaultActions holds disposed objects from being GCed

4 participants