0

I have a map based app, that uses the MKMapView as main view. While my iPad is connected to Xcode, I can see in the debug navigator that the memory usage keeps increasing when zooming and panning around the map. I suppose iOS is caching the map tiles, but doesn't release them before the MkMapView is destroyed.

Is there any way to force MkMapView to clear all cache?

If I continue to pan and zoom around my app finally crashes when memory usage is at 3Gb.

Zifigo
  • 196
  • 8
  • Possible duplicate of [How to clear the cache of mkmapview](https://stackoverflow.com/questions/22553085/how-to-clear-the-cache-of-mkmapview) – dengApro Nov 14 '18 at 01:19

1 Answers1

0
func applicationDidReceiveMemoryWarning(_ application: UIApplication) {
    URLCache.shared.removeAllCachedResponses()
}

Clears the receiver’s cache, removing all stored cached URL responses.


Are you setting the reuse identifier on your annotation views? (This means the system can detach those views and only keep a small number of views in memory at once. It also increases scrolling performance, because scrolling will reuse the detached views.)

Use this method to get an annotation view to be reused:

// Used by the delegate to acquire a reusable annotation view, or create a new view for registered class, in lieu of allocating a new one.
    open func dequeueReusableAnnotationView(withIdentifier identifier: String) -> MKAnnotationView?
dengApro
  • 3,848
  • 2
  • 27
  • 41
  • I tried firing that every 5 seconds, doesn't change anything. Memory usage still grows. – Zifigo Nov 14 '18 at 17:56
  • firing that every 5 seconds is intuitive, and a little weird. – dengApro Nov 15 '18 at 01:30
  • I have a scheduled task that runs every 5 seconds, so I added it there for testing, to see if it would keep memory usage from growing if constantly panning through the maps. – Zifigo Nov 15 '18 at 06:44