NativeScript / NativeScript/android
Memory Leak on Navigation due to references not being removed from the HashMap
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- C++
- Star
- 563
- Fork
- 144
- Merge trung bình
- 10 giờ 46 phút
- Pull request đã merge (30 ngày)
- 14
Mô tả
Environment
- CLI: 8.0.2
- Cross-platform modules:
- Android Runtime: 8.0.0
- iOS Runtime (if applicable):
- Plugin(s):
Describe the bug
When navigating the old fragments are still being referenced in the HashMap so the Garbage Collector doesn't collect them causing a memory leak.
When the navigation's 'clearHistory: true' the backstack is emptied properly but the memory leak remains.
When 'clearHistory: false' you can see all the old pages still in the backstack with different Id names even if they are the same page.
To Reproduce
ns create my-drawer-js --template @nativescript/template-drawer-navigation
Open up the profiler in Android Studio
Go to Memory and start a new profiling session
Navigate to a different page in the template app
Go back to profiler and Dump Java Heap

Click the Leaks link

Click the FragmentClass

Click the Instance

Click the References Tab and check the 'Show nearest GC root only' Option

The FragmentClass instance can't be released because of the references in the HashMap I believe.
This leak is also caught using leak canary

Expected behavior
Fragments should be getting completely removed from memory
Sample project
I used the most vanilla template I could to make sure issues weren't coming from frameworks or plugins
https://www.npmjs.com/package/@nativescript/template-drawer-navigation
Additional context
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Tái hiện leak bằng @nativescript/template-drawer-navigation, sau đó kiểm tra heap dump của Android Studio và các tham chiếu LeakCanary được mô tả trong issue. Theo dõi các instance FragmentClass bị HashMap giữ lại trong quá trình điều hướng và xác minh rằng các page đã được clear hoặc thay thế có thể được garbage collector thu gom mà không giữ lại các fragment cũ.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- android
- Lĩnh vực
- mobile, performance
- 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
- 32/100