NativeScript / NativeScript/android
Memory Leak on Navigation due to references not being removed from the HashMap
Nessuno ha ancora preso questa issue.
- Lingua principale
- C++
- Stelle
- 563
- Fork
- 144
- Merge medio
- 10h 46m
- PR unite (30g)
- 14
Descrizione
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
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Riproduci il leak con @nativescript/template-drawer-navigation, quindi esamina l’heap dump di Android Studio e i riferimenti di LeakCanary descritti nell’issue. Traccia le istanze di FragmentClass trattenute dalla HashMap durante la navigazione e verifica che le pagine cancellate o sostituite possano essere raccolte dal garbage collector senza trattenere i fragment precedenti.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- android
- Ambito
- mobile, performance
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 32/100