flutter / flutter/devtools

Disposed widget is still shown in Memory

Offen
#6,618 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
P2 screen: memory
Vorherrschende Sprache
Dart
Sterne
1.7k
Forks
404
Ø Merge
6 T. 17 Std.
Gemergte PRs (30 T.)
18

Beschreibung

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

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.