iOS6 MKMapView using a ton of memory, to the point of crashing the app, anyone else notice this?

Jeremy Fox picture Jeremy Fox · Sep 28, 2012 · Viewed 22.4k times · Source

Has anyone else, who's using maps in their iOS 6 apps, noticing extremely high memory use to the point of receiving memory warnings over and over to the point of crashing the app?

I've ran the app through instruments and I'm not seeing any leaks and until the map view is created the app consistently runs at around ~3mb Live Bytes. Once the map is created and the tiles are downloaded the Live Bytes jumps up to ~13mb Live Bytes. Then as I move the map around and zoom in and out the Live Bytes continuos to climb until the app crashes at around ~40mb Live Bytes. This is on an iPhone 4 by the way. On an iPod touch it crashes even earlier.

I am reusing annotation views properly and nothing is leaking. Is anyone else seeing this same high memory usage with the new iOS 6 maps? Also, does anyone have a solution?

Answer

Jeremy Fox picture Jeremy Fox · Jan 7, 2013

After a lot of playing around and testing different ideas, some of which were mentioned here, the final solution that worked for me was as follows.

  • Instead of creating new MKMapView's as needed in the app, I added an mkMapView property to my AppDelegate and only created it when needed. Once it has been created, it lives in the AppDelegate forever and I reuse that single instance everywhere needed. This really helped in reducing the amount of memory being used as I was previously instantiating a couple different MKMapView's and both were burning through memory pretty quickly.

  • I also found that iOS 6 Maps handles releasing memory very well once a Memory Warning has been received. Yes, it does use up more memory while zooming and panning, but seems to be responding to Memory Warnings appropriately.

  • The last thing I had to do was work on reducing my overall initial memory footprint. I noticed I was starting off way higher than I expected so that was also contributing to the crashes I was receiving related to memory. Once I got the initial footprint down, let MKMapView handle releasing it's memory during Memory Warnings, and made sure I only had 1 instance of MKMapView that I could reuse throughout the app, everything is running fine.