1

I am using iOS Google Maps in my app. I've been looking for memory leaks as of lately as I noticed the Memory started spiking whenever I would zoom out. Both on simulator and my actual iPhone X device experience such memory spikes when zooming out. I am also zooming out because I am using the marker clustering feature.

I've done some research on different ways to detect memory leaks such as enabling sound actions on breakpoints and looking at Backtrace tree for strong references. It seems that there is a strong reference when I configure my GMSMapView (Code below).

func configureMapView() {
    guard let location = locationManager.location else { return }
    let camera = GMSCameraPosition.camera(withLatitude: location.coordinate.latitude, longitude: location.coordinate.longitude, zoom: 16.5)
    mapView = GMSMapView.map(withFrame: CGRect.zero, camera: camera)
    mapView.isMyLocationEnabled         = true
    mapView.settings.compassButton      = true
    mapView.settings.rotateGestures     = false
    mapView.settings.tiltGestures       = false
    view = mapView
}

Xcode is pointing to this line that has a strong reference.

mapView = GMSMapView.map(withFrame: CGRect.zero, camera: camera)

Is this strong reference the reason why memory usage spikes up when zooming out? Also, not entirely sure how to fix this strong reference with Google Maps, any help would be appreciated!

syds
  • 322
  • 3
  • 12
  • See [here](https://stackoverflow.com/questions/60149983/how-to-fix-memory-leaks-in-ios-applications/60157622#60157622). Learn how to use the memory graph debugger. That can help pinpoint the issue. – mfaani Feb 10 '20 at 22:45
  • Hi @Honey, thanks for the link, I watched the video you linked to and it was very informative. I looked through the debugger on my end and didn't see any purple warnings of a leak, nor did I see a reference cycle when I clicked on the root of GMSMapView in the debugger. I can only assume that I don't have any strong references and that it's normal of Google Maps to eat up so much memory. – syds Feb 10 '20 at 23:07
  • there are two types of memory issues. One type does show up with the purple indicator. The other doesn't. The way you find out if you have an **abandoned** memory (not leak or reference cycle) is to go back and forth a flow multiple times and then check within the left panel of memory graph debugger and see if you have multiple instances of a class in memory. Try that too. But likely you don't such an issue. If it's not you then you might want to open a ticket with google-maps – mfaani Feb 10 '20 at 23:09
  • Hey, did you find out how to solve this at the end? – oneshot Jan 24 '21 at 01:21

0 Answers0