android-maps-compose
android-maps-compose copied to clipboard
Memory leak in new map renderer with compose map with PolyLines
In our app we have out-of-memory errors since we updated to android compose maps 4.3.0.
This is related to the new map renderer which became default in maps sdk 18.2.0, see https://developers.google.com/maps/documentation/android-sdk/renderer
It is caused by drawing polylines on a compose map. When the lines are not drawn the memory-leak does not occur anymore. We work around this for now by enabling the legacy renderer in this way:
MapsInitializer.initialize(applicationContext, Renderer.LEGACY) { }
Environment details
Android, any version android-maps compose from version 4.1.0 and higher, (since the use of maps sdk 18.2.0 where the new map renderer became default, see https://developers.google.com/maps/documentation/android-sdk/renderer)
Steps to reproduce
- create a map which shows several 100 polylines
- showing the map is enough on some phone to crash the app with an out of memory error. Some need switching back and forth a few times (between overview and details for example)
- memory usage is rising until the garbage collector can not get more memory and kills the app.
Code example
This is how we create some of the polylines:
detailTracks.forEach { points ->
Polyline(
points = points,
width = 3F.dp,
color = color,
zIndex = 100F,
)
}