android-maps-compose icon indicating copy to clipboard operation
android-maps-compose copied to clipboard

Memory leak in new map renderer with compose map with PolyLines

Open bluevoidnl opened this issue 1 year ago • 5 comments

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

  1. create a map which shows several 100 polylines
  2. 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)
  3. 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,
           )
       }

bluevoidnl avatar Dec 21 '23 13:12 bluevoidnl