flutter / flutter/devtools

Disposed widget is still shown in Memory

Abierto
#6,618 0 comentarios 0 reacciones 0 asignados Ver en GitHub
P2 screen: memory
Lenguaje dominante
Dart
Estrellas
1.7k
Forks
404
Merge medio
6 d 17 h
PR fusionados (30 d)
18

Descripción

# 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.

![image](https://github.com/flutter/devtools/assets/114375528/543b4879-9a2c-4219-b88c-3ef74566ce12)

![image](https://github.com/flutter/devtools/assets/114375528/6c20a981-ad2f-476e-b7f7-3119cd883402)
Also how to interpret the retaining path for `Home`? where is the `_List`?

Thank you in advance!

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.