Disposed widget is still shown in Memory
- Lingua principale
- Dart
- Stelle
- 1.7k
- Fork
- 404
- Merge medio
- 6g 17h
- PR unite (30g)
- 18
Descrizione
# 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!
Guida per i contributori
Apri la guida per i contributori
Direzione di ricerca
Inizia eseguendo la riproduzione Dart fornita e ispezionando il Memory panel e il retaining path dopo che il Home widget è stato rimosso e la garbage collection è stata attivata. L'issue non indica file di progetto o test, quindi individua prima la gestione delle allocazioni e dei retaining paths del Memory panel. Il lavoro è completato quando i widget eliminati non vengono più segnalati erroneamente come allocati e il retaining path può essere interpretato.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- dart
- Ambito
- devtools
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 42/100