Disposed widget is still shown in Memory
- Langage dominant
- Dart
- Étoiles
- 1.7k
- Forks
- 404
- Merge moyen
- 6 j 17 h
- PR mergées (30 j)
- 18
Description
# Sample code
```
void main() {
runApp(const MainApp());
}
class MainApp extends StatefulWidget {
const MainApp({super.key});
@override
State createState() => _MainAppState();
}
class _MainAppState extends State with WidgetsBindingObserver {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Navigator(
initialRoute: Routes.root.path,
onGenerateRoute: mainAppRouteFactory,
),
),
);
}
}
enum Routes {
root,
home;
String get path => toString().split('.').last;
}
RouteFactory mainAppRouteFactory = (settings) {
final routeName =
Routes.values.firstWhere((route) => route.path == settings.name);
switch (routeName) {
case Routes.root:
return PageRouteBuilder(
settings: settings,
pageBuilder: (context, _, __) => const Root(),
);
case Routes.home:
return PageRouteBuilder(
settings: settings,
pageBuilder: (context, _, __) => const Home(),
);
}
};
class Home extends StatefulWidget {
const Home({super.key});
@override
State createState() => _HomeState();
}
class _HomeState extends State {
@override
void dispose() {
super.dispose();
print('home disposed');
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
leading: BackButton(
onPressed: Navigator.of(context).pop,
),
),
);
}
}
class Root extends StatelessWidget {
const Root({super.key});
@override
Widget build(BuildContext context) {
return TextButton(
onPressed: () => Navigator.of(context).pushNamed(Routes.home.path),
child: const Text('home'));
}
}
```
# Steps to reproduce
1. tap on the "home" button in the `Root` page to push `Home` page
2. tap on the back button on `Home` page to dismiss it
3. observe that console has the print `flutter: home disposed` as expected
4. observe that Flutter Inspector in Flutter DevTools no longer has the `Home` widget in the widget tree as expected
5. observe that in the Memory panel of Flutter DevTools, `Home` is still shown as allocated, even after manually pressing `GC` button to do a garbage collection. This is not expected, because this will give false positives for memory leaks.


Also how to interpret the retaining path for `Home`? where is the `_List`?
Thank you in advance!
Guide de contribution
Ouvrir le guide de contribution
Piste de recherche
Commencez par exécuter la reproduction Dart fournie et inspectez le Memory panel ainsi que le retaining path après la suppression du Home widget et le déclenchement du garbage collection. L’issue ne nomme aucun fichier de projet ni aucun test ; commencez donc par localiser la gestion des allocations et des retaining paths du Memory panel. Le travail est terminé lorsque les widgets supprimés ne sont plus signalés à tort comme alloués et que le retaining path peut être interprété.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- dart
- Domaine
- devtools
- Type d'issue
- Bug
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Activité
- À l'abandon
- Clarté
- Plutôt claire
- Accessibilité débutants
- 42/100