mapbox-maps-android
mapbox-maps-android copied to clipboard
Mapbox SDK memory leak detected!
Environment
- Android OS version: V12
- Devices affected: Google Pixel 6
- Maps SDK Version: V10.7.0
Mapbox SDK memory leak detected! MapboxMap object (accessing getStyle) should not be stored and used after MapView is destroyed.
I also have this issue.
I have this issue when popping back to the map fragment using androids navigation components. I believe it may be due to the new embedded mapView lifecycle components (v10.0.0-rc.5 onwards) destroying the map after navigation.
As a temporary fix, you can exclude the 'maps-lifecycle' plugin from the com.mapbox.maps dependency (Documentation states that this plugin was added into the com.mapbox.maps dependency from v10.0.0-rc.5). While this does remove the automatic lifecycle handling from the application - it allows for navigation back to a map fragment.
Tested and working with com.mapbox.maps:android:10.8.0-rc.1
Hey all!
This error log is printed when Style
or MapboxMap
object is stored as local variable and gets accessed after style was reloaded or map view was destroyed. It's not necessarily the leak itself, more of a warning that outdated object is used. In order to understand what's happening please provide more information / provide sample code reproducing it.
@caustin13 - about your use-case with fragments and navigation components - we do track that internally and plan to fix it in next 2 weeks.
Hello there,
In my case , This Memory leak because i call pointAnnotationManager.onDestroy()
in onDestroy
.
the solution, in v10 the mapbox handle removing annotations without call pointAnnotationManager.onDestroy()
https://docs.mapbox.com/android/maps/guides/migrate-to-v10/#annotations
In pre-v10, AnnotationManager needed to be recycled in the onDestroy method of the host activity. In v10, there is no need to do it manually because AnnotationManager will be cleaned automatically along with the host, AnnotationPlugin.
I also have this issue. Any solution?
This issue appears to me when LocationPuck is enabled, and I navigate away from the screen.
E/Mapbox: [maps-android\Mbgl-Style]: Mapbox SDK memory leak detected! Style object (accessing setStyleLayerProperty) should not be stored and used after MapView is destroyed or new style has been loaded.
E/Mapbox: [maps-android\Mbgl-Style]: Mapbox SDK memory leak detected! Style object (accessing styleLayerExists) should not be stored and used after MapView is destroyed or new style has been loaded.
I receive this error in an infinite loop on my run
logs.
Dependencies:
implementation 'com.google.android.gms:play-services-location:20.0.0'
implementation 'com.mapbox.maps:android:10.8.1'
- using Jetpack Compose approach with NavHost and NavController
- notice
play-services-location:21.0.0'
will crash the application altogether. Though probably a separate issue, using20.0.0
for now. https://github.com/mapbox/mapbox-maps-android/issues/1715#issuecomment-1281086663
@swathysreenivas @IsaacTrevino as @kiryldz had mentioned - the message you see in logs means you use Style object after MapView is destroyed, so please check if this is the case, e.g. lifecycle and when Map is destroyed.
notice play-services-location:21.0.0' will crash the application altogether. Though probably a separate issue, using 20.0.0 for now.
This is known issue - Google play services v21 have breaking change and are not compatible with the existing Maps SDK, more info https://github.com/mapbox/mapbox-maps-android/issues/1752. Please keep using v20 for now.
@yunikkk @kiryldz thank you for responding
I dont see how I am calling a Style object
after the MapView is destroyed since Mapbox handles the LocationPuck rendering. All I do is enable it with the location plugin location.enable
and upon switching between mapView and another page, it breaks.
Though it may not break right away it does after you switch repeatedly. Could this be a bug within the location plugin lifecycle not being synced with MapView?
I can confirm a similar issue with the mapbox location plugin. I store no references to the style and have narrowed the problem down to simply enabling the location plugin and using the LocationPuck. Without it, no warning is ever raised.
Setting enabled to false
will hide these warnings, but will also obviously not show any puck (which is undesired). This code is enough to trigger these warnings when switching between pages:
mapView.location.updateSettings {
enabled = true
}
If anyone wants to try removing the plugin like @caustin13 suggested, here's how
implementation('com.mapbox.maps:android:10.8.1'){
exclude group: 'com.mapbox.plugin', module: 'maps-lifecycle'
}