Search code examples
iosswiftmemory-managementgoogle-maps-sdk-iosgmsmapview

GMSMapView cached tiles are held in memory after zooming, leading to high memory usage and bad App performance


In my app i'm presenting a ViewController which displays a GMSMapView. Neither the ViewController nor the GMSMapView are supposed to be dismissed until the app is on the foreground, so the GMSMapView object is never deallocated, and since i'm also showing a GMSPanoramaView, with both being pretty expensive objects, i'm having a performance issue related to high memory usage.

After the app launch, when GMSMapView is initialized, the memory usage is relatively low and totally fine for my app requirements.

The problem comes after i zoom in, i'm experiencing a high memory increase which is never deallocated even after i zoom out. I'm not sure, but it looks to me like something is being cached by the SDK and never freed. In the image down below (testing device: iPhone XR), you can see clearly the issue, where the first peak occurs while i'm zooming and from then on memory usage never decreases even after the zoom level goes back to 0: enter image description here

I'm trying to decrease the memory usage related to the cache(?) but i have no idea on how to actually do it or even if it is possible. From my understaing from the docs, the .clear() method only affects markers and overlays. I've also notice the stopRendering() method that could have been useful, it is deprecated tho.

On a side note, to do some general performance improvements related to GMSMapView, i'm already setting the MapView property .preferredFrameRate equal to .conservative to reduce the rendering frame rate, and also setting .isBuildingsEnabled = false and .isIndoorEnabled = false to avoid useless caching.

My question is: using GoogleMaps SDK, it is possible to prevent the up above mentioned caching or to free the memory once the map is zoomed out? If not, is there anything else i can do to reduce the high memory usage related to GMSMapView?

EDIT: this might come in handy for someone else, thus i'm adding some more GoogleMaps SDK optimization tips. I'm using a custom map style and i've found out, from my personal experience, that using Cloud-based Map Styling (currently in beta) is a bit faster in rendering map tiles than the classic .mapStyle = try GMSMapStyle(contentsOfFileURL: file) approach.


Solution

  • After a bit of research, I've found out that there is an open issue regarding the high memory usage: https://issuetracker.google.com/issues/35826246. This was opened 6 years ago, not sure it will ever be solved, shame on Google. Not much else to do, apart from starring the issue and hoping for a fix.