mapbox / mapbox/mapbox-maps-android

MapView Memory leak

Aperta
#2,184 12 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

auto-triaged bug :beetle:
Lingua principale
Kotlin
Stelle
578
Fork
161
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

Environment

  • Android OS version: Any
  • Devices affected:
  • Maps SDK Version: 10.16.0 and 10.10.1 (maybe others bellow it too)

Observed behavior and steps to reproduce

A memory leak started to occur a while ago, it doesn't seem be related with any changes in our implementation but something internal in the SDK.
The leak happens every time we enter a screen that has the map view.
Also, we were only able to reproduce it when using Don't keep activities settings

┬───
│ GC Root: Global variable in native code
│
├─ com.mapbox.maps.NativeObserver instance
│    Leaking: UNKNOWN
│    Retaining 114.0 kB in 2977 objects
│    ↓ NativeObserver.onMapLoadErrorListeners
│                     ~~~~~~~~~~~~~~~~~~~~~~~
├─ java.util.concurrent.CopyOnWriteArraySet instance
│    Leaking: UNKNOWN
│    Retaining 40 B in 4 objects
│    ↓ CopyOnWriteArraySet.al
│                          ~~
├─ java.util.concurrent.CopyOnWriteArrayList instance
│    Leaking: UNKNOWN
│    Retaining 28 B in 3 objects
│    ↓ CopyOnWriteArrayList[0]
│                          ~~~
├─ com.mapbox.maps.StyleObserver instance
│    Leaking: UNKNOWN
│    Retaining 113.4 kB in 2920 objects
│    ↓ StyleObserver.styleLoadedListener
│                    ~~~~~~~~~~~~~~~~~~~
├─ com.mapbox.maps.MapboxMap$$ExternalSyntheticLambda1 instance
│    Leaking: UNKNOWN
│    Retaining 113.2 kB in 2914 objects
│    ↓ MapboxMap$$ExternalSyntheticLambda1.f$0
│                                          ~~~
├─ com.mapbox.maps.MapboxMap instance
│    Leaking: UNKNOWN
│    Retaining 113.2 kB in 2913 objects
│    ↓ MapboxMap.gesturesPlugin
│                ~~~~~~~~~~~~~~
├─ com.mapbox.maps.plugin.gestures.GesturesPluginImpl instance
│    Leaking: UNKNOWN
│    Retaining 3.5 kB in 118 objects
│    context instance of com.example.MainActivity with mDestroyed = false
│    ↓ GesturesPluginImpl.mapPluginProviderDelegate
│                         ~~~~~~~~~~~~~~~~~~~~~~~~~
├─ com.mapbox.maps.MapController instance
│    Leaking: UNKNOWN
│    Retaining 105.1 kB in 2598 objects
│    ↓ MapController.pluginRegistry
│                    ~~~~~~~~~~~~~~
├─ com.mapbox.maps.plugin.MapPluginRegistry instance
│    Leaking: UNKNOWN
│    Retaining 103.5 kB in 2556 objects
│    ↓ MapPluginRegistry.plugins
│                        ~~~~~~~
├─ java.util.LinkedHashMap instance
│    Leaking: UNKNOWN
│    Retaining 608 B in 18 objects
│    ↓ LinkedHashMap["MAPBOX_ATTRIBUTION_PLUGIN_ID"]
│                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
├─ com.mapbox.maps.plugin.attribution.AttributionViewPlugin instance
│    Leaking: UNKNOWN
│    Retaining 94 B in 3 objects
│    ↓ AttributionViewPlugin.attributionView
│                            ~~~~~~~~~~~~~~~
├─ com.mapbox.maps.plugin.attribution.AttributionViewImpl instance
│    Leaking: UNKNOWN
│    Retaining 2.7 kB in 58 objects
│    View not part of a window view hierarchy
│    View.mAttachInfo is null (view detached)
│    View.mWindowAttachCount = 0
│    mContext instance of com.example.MainActivity with mDestroyed = false
│    ↓ View.mParent
│           ~~~~~~~
├─ com.mapbox.maps.MapView instance
│    Leaking: UNKNOWN
│    Retaining 90.6 kB in 2261 objects
│    View not part of a window view hierarchy
│    View.mAttachInfo is null (view detached)
│    View.mID = R.id.map_view
│    View.mWindowAttachCount = 0
│    mContext instance of com.example.MainActivity with mDestroyed = false
│    ↓ View.mParent
│           ~~~~~~~
╰→ androidx.constraintlayout.widget.ConstraintLayout instance
     Leaking: YES (ObjectWatcher was watching this because com.example.
​     MapboxFragment received Fragment#onDestroyView() callback (references to its views should be cleared to prevent
​     leaks))
​     Retaining 84.3 kB in 2155 objects
​     key =
​     watchDurationMillis = 5808
​     retainedDurationMillis = 808
​     View not part of a window view hierarchy
​     View.mAttachInfo is null (view detached)
​     View.mID = R.id.map_root_container
​     View.mWindowAttachCount = 0
​     mContext instance of com.example.MainActivity with mDestroyed = false

Expected behavior

No memory leak.

Notes / preliminary analysis

Additional links and references

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

Inizia riproducendo il leak su Android con “Don’t keep activities” abilitato, usando le versioni di MapView e SDK indicate. Ispeziona i listener di NativeObserver, StyleObserver, MapboxMap, il registro dei plugin e la vista di attribuzione mostrata nella traccia del leak. Il lavoro è completato quando entrare e uscire ripetutamente dalla schermata della mappa non mantiene più l’Activity distrutta né le sue view.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
android, kotlin
Ambito
mobile-dev, performance
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
30/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.