NativeScript / NativeScript/android

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

Abierto
#1,669 2 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Lenguaje dominante
C++
Estrellas
563
Forks
144
Merge medio
10 h 46 min
PR fusionados (30 d)
14

Descripción

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

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Reproduce la fuga con @nativescript/template-drawer-navigation y, después, inspecciona el volcado de memoria de Android Studio y las referencias de LeakCanary descritas en el issue. Rastrea las instancias de FragmentClass retenidas por el HashMap durante la navegación y verifica que las páginas eliminadas o reemplazadas puedan ser recolectadas por el garbage collector sin retener fragmentos antiguos.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
android
Área
mobile, performance
Tipo de issue
Error
Dificultad
4/5
Tiempo estimado
3-5 días
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
32/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.