googlemaps / android-maps-compose

Jetpack Compose composables for the Maps SDK for Android
https://developers.google.com/maps/documentation/android-sdk/maps-compose
Apache License 2.0
1.16k stars 139 forks source link

Memory leak in new map renderer with compose map with PolyLines #487

Open bluevoidnl opened 10 months ago

bluevoidnl commented 10 months ago

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,
            )
        }
wangela commented 10 months ago

If you would like to upvote the priority of this issue, please comment below or react on the original post above with :+1: so we can see what is popular when we triage.

@bluevoidnl Thank you for opening this issue. 🙏 Please check out these other resources that might help you get to a resolution in the meantime:

This is an automated message, feel free to ignore.

kikoso commented 10 months ago

Hi @bluevoidnl . This seems like an issue that is being caused by the new Renderer, could you file a new issue here?

I can see some OutOfMemory errors, but at this point not enough to determine how this is happening. A temporary fix would be to opt out from the new renderer and stay on the legacy one, but if this is an issue should be fixed. I am bringing it up with the responsible team.

hanna-h commented 10 months ago

Hi @kikoso ,

I work together with @bluevoidnl . I created a new issue here.

samargulies commented 8 months ago

I am also seeing this issue when I upgrade to the new rendered on my map that is rendering several hundred polylines.

LOOHP commented 6 months ago

I'm also facing this issue when I add lots of Polylines on a map. Crashes for out of memory on the new renderer, but not when switching back to the legacy one. However, according to the issue, running out of memory is the intended behaviour. Seems like the only way now is to reduce the number of shapes.