Disposed widget is still shown in Memory
- Ngôn ngữ chính
- Dart
- Star
- 1.7k
- Fork
- 404
- Merge trung bình
- 6 ngày 17 giờ
- Pull request đã merge (30 ngày)
- 18
Mô tả
# 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!
Hướng dẫn đóng góp
Hướng nghiên cứu
Bắt đầu bằng cách chạy bản tái hiện Dart được cung cấp và kiểm tra Memory panel cùng retaining path sau khi Home widget bị loại bỏ và garbage collection được kích hoạt. Issue không nêu tệp dự án hoặc test nào, vì vậy trước tiên hãy xác định phần xử lý allocation và retaining path của Memory panel. Hoàn thành khi các widget đã bị dispose không còn bị báo cáo sai là đã được allocate và retaining path có thể được diễn giải.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- dart
- Lĩnh vực
- devtools
- Loại issue
- Lỗi
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 42/100