MKMapView using a lot of memory every time I load its view

I have a pretty simple application with several view controllers. The second view controller has MKMapView. It is configured correctly and works fine. The problem is that every time I load his view, the memory usage jumps ~ 30 MB and never returns, so every time I enter the view, he continues to jump and, in the end, becomes super high. I tried to remove the map display when I left the controller as follows:

override func viewWillDisappear(animated: Bool) { map.removeFromSuperview() } 

but it does not affect memory. The map views delegate has its controller installed.

I tried checking for leaks with the Xcode tools, but didn't find anything.

Does anyone know how to fix this?

thanks

EDIT: Adding this seems to work:

 func removeNastyMapMemory() { map.mapType = MKMapType.Hybrid map.delegate = nil map.removeFromSuperview() map = nil } override func viewWillDisappear(animated: Bool) { removeNastyMapMemory() } 
+5
source share
1 answer

This is not a Swift issue since Objective-C days. Possible solutions to this problem depend on the situation and the behavior of the application.

  • If you use the map several times (or places), create only one (shared) instance. What you can use whenever you want.

  • Or, if you use it only once, try the fooobar.com/questions/210256 / ... solution here. This can help. Reduce a bit. But not all.

+5
source

Source: https://habr.com/ru/post/1246442/


All Articles