Repository navigation
Memory Leak: _RouterState doesn't dispose _RestorableRouteInformation #134205
Copy link
Copy link
Closed
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work listf: routesNavigator, Router, and related APIs.Navigator, Router, and related APIs.frameworkflutter/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
Activity
cc @polina-c
- addedin triagePresently being triaged by the triage teamPresently being triaged by the triage teamframeworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.f: routesNavigator, Router, and related APIs.Navigator, Router, and related APIs.team-frameworkOwned by Framework teamOwned by Framework teamand removedin triagePresently being triaged by the triage teamPresently being triaged by the triage team
on Sep 7, 2023 - addedP2Important issues not at the top of the work listImportant issues not at the top of the work listtriaged-frameworkTriaged by Framework teamTriaged by Framework team
on Sep 12, 2023 Note: leak_tracking is off for web.
It does not mean we should stop disposing objects for web though.It seems _RouterState is used after dispose.
And it seems this call is result ofSchedulerBinding.instance.addPostFrameCallback(_reportRouteInformation);.@goderbauer, do you have context?
Is there a way to cancel the callback in disposal?Reacted by Kostia SokolovskyiThat looks like a bug, we should short circuit the postframecallback if it is disposed
- added a commit that references this issue
on Oct 14, 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 -vand a minimal reproduction of the issue.- locked as resolved and limited conversation to collaborators
on Oct 28, 2023 - added a commit that references this issue
on Jun 12, 2026
Metadata
Metadata
Assignees
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work listf: routesNavigator, Router, and related APIs.Navigator, Router, and related APIs.frameworkflutter/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
Is there an existing issue for this?
Steps to reproduce
PR that marks the issue: #133803
_RouterStatecreates_RestorableRouteInformation:flutter/packages/flutter/lib/src/widgets/router.dart
Line 602 in 3744050
_RouterStatedoesn't dispose_routeInformation:flutter/packages/flutter/lib/src/widgets/router.dart
Lines 731 to 738 in 3744050
Please note that the simple
dispose()of_routeInformationis not working.Tests on Mac work well but on the web fail: https://logs.chromium.org/logs/flutter/buildbucket/cr-buildbucket/8770691241593985297/+/u/run_test.dart_for_web_canvaskit_tests_shard_and_subshard_1/test_stdout#:~:text=A%20_RestorableRouteInformation%20was%20used%20after%20being%20disposed.
The test fails on the web with the next error:
A _RestorableRouteInformation was used after being disposed. Once you have called dispose() on a _RestorableRouteInformation, it can no longer be used..This happens while trying to access the
valueof_routeInformationin_reportRouteInformation()method.flutter/packages/flutter/lib/src/widgets/router.dart
Lines 638 to 648 in 3744050
Expected results
_RouterStatedisposes_routeInformation.Actual results
_RouterStatedoesn't dispose_routeInformation.Code sample
Test which reveals the leak
Flutter Doctor output
Doctor output