I've noticed that my app leaks memory, but if I take the MKMapView
out the memory problem goes away.
To test the theory, I made a dead simple project that has a view that pushes a view with a MKMapView
in it and pops and pushes. Nothing more. No code in the view controllers, everthing done via storyboard.
If I go back and forth to the map view, it starts about 3MB after doing pushing and popping the view with the map in it this about 15 times the memory is around 230MB.
Anyone else seen this? Seems like a pretty big bug. Is there a different way to use MKMapView
that will prevent it from leaking so much?
The best solution I have found is to have an instance of MKMapView in your delegate, you will allocate it only once.
Then anytime you need a MapView, you just use the one from the delegate.
In my case i needed to clean the annotations from it as soon as the view willDisappear ( to not have older annotations on the map ).
I had faced the same issue and (thanks to Stackoverflow) fixed it by changing
MKMapType
inviewWillDisappear
and deallocating/setting its delegate to nil.As it still sends message to delegates. This is documented in MKMapViewDelegate Protocol Reference:.
hope this helps
Swift Version: