NativeScript / NativeScript/android
Memory Leak on Navigation due to references not being removed from the HashMap
まだ誰も着手していません。
- 主要言語
- C++
- スター
- 563
- フォーク
- 144
- 平均マージ
- 10時間 46分
- マージ済み PR(30日)
- 14
説明
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
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
@nativescript/template-drawer-navigation でリークを再現し、その後、issue に記載されている Android Studio のヒープダンプと LeakCanary の参照を調査します。ナビゲーション中に HashMap によって保持される FragmentClass インスタンスを追跡し、クリアまたは置き換えられたページが古いフラグメントを保持せずにガベージコレクションされることを確認します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- android
- 領域
- mobile, performance
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 32/100