I have followed the advice available in several SO questions, like this one, in order to release MKMapView
from memory - my code below
- (void)viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];
self.map.mapType = MKMapTypeHybrid;
self.map.showsUserLocation = NO;
self.map.delegate = nil;
[self.map removeFromSuperview];
self.map = nil;
self.locationManager.delegate = nil;
}
In part, it works, but not entirely. Let me provide some data.
Below is the memory allocation recording from Instruments.
The two red flags (Generations) indicate the states before I displayed MKMapView
in a modal view controller and after I have dismissed it. MKMapView
seems to get deallocated. For instance, if I filter Statistics stack in Instruments for MKMapView
, the object does indeed appear when the modal view is presented, and disappears once it's closed. However, having dismissed the map view, I still have 30+ MB of memory that has not been freed up.
Generation B (second red flag) data shows that there is a large number of objects (and non-objects) that are holding this memory.
When I look at extended details of one of those instances, it usually shows a stack trace that features private classes that, I guess, are related to map drawing
Does anyone know how to free up all that data? Is there some cache I could/should clean?