NativeScript / NativeScript/android

Memory Leak on Navigation due to references not being removed from the HashMap

Aperta
#1,669 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

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
image

Click the Leaks link
image

Click the FragmentClass
image

Click the Instance
image

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

The FragmentClass instance can't be released because of the references in the HashMap I believe.

This leak is also caught using leak canary
image

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

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. 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

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.