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?
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.
I'm also having this problem and its driving me nuts. Trying to figure out a hotfix based on mateo's post, this is what I came up with:
- (void)applyMapViewMemoryHotFix{
switch (self.mkMapView.mapType) {
case MKMapTypeHybrid:
{
self.mkMapView.mapType = MKMapTypeStandard;
}
break;
case MKMapTypeStandard:
{
self.mkMapView.mapType = MKMapTypeHybrid;
}
break;
default:
break;
}
[self.mkMapView removeFromSuperview];
self.mkMapView = nil;
}
Im not sure why, but the combination of removing from superview and then setting to nil really reduces the memory usage. I call this method in the controller's viewDidDisappear.
Other things I tried but without significant effect:
1) Creating autoreleasepool around alloc init of the mkMapView
2) Setting displayed region around lat 84 lon -30 as I thought Vector Information in the Arctic might not be as dense... However, doesnt help ;)
This issue is very serious and causes our app to be unstable and cause tons of memory warnings in iOS 6. Sure hope that Apple releases a better hotfix than mine... soon!!
Please critique my hotfix and come up with more effective methods to cut memory usage when discarding a map. Thanks!
I experience the same issue.
Memory is never released after zoom and change location.
The only trick i've found is to change map type after memory warning.
This issue is still present in iOS 9 - unless you do this.
Segue to and from a view controller with a map view that has been set up in a story board causes a crash (for me) after about 10-15 show and dismiss cycles.
Now it appears the fix is simple. Adding this
override func viewDidDisappear(animated: Bool) {
super.viewDidDisappear(animated)
mapView.removeFromSuperview()
}
Seems to have fix the issue, the can cycle to and from more than 20 times, and no issue. No crash!!
Hope this helps. This was a frustrating problem and glad its solved.
My footprint was: 2.48; 19.51; 49.64; 12.60 which is: Memory before loading the mapView, after loading the mapView, after zooming in/out a bit, and after releasing the mapView (which is quite annoying, even after releasing the mapView, I keep 10MB increment and it doesn't go down!)
Anyway, I am not using an IBOutlet for the MapView anymore, I am creating everything in code instead. The new footprint is now: 2.48; 19.48; 38.42; 12.54.
Still working on putting the bi*** down.
Not a solution but simply a trick...
... change mapType => mapkit release memory.
Even if this change is for a fraction of second.
I've got the same feeling and don't know how to release
this memory
, even when MKMapView
is not used.
I've released controller, MKMapView
, container view... memory
is still used.
Don't remember to experience this with old MKMapView
in iOS5.
- (void)applyMapViewMemoryHotFix{
switch (self.mapView.mapType) {
case MKMapTypeHybrid:
{
self.mapView.mapType = MKMapTypeStandard;
}
break;
case MKMapTypeStandard:
{
self.mapView.mapType = MKMapTypeHybrid;
}
break;
default:
break;
}
self.mapView.mapType = MKMapTypeStandard;
}
-(void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated
{
[self applyMapViewMemoryHotFix];
}
I'm receiving same issue -
I'm not entirely sure about this, but could it be that the new apple maps preloads a huge area of the map to cater for offline navigation?
If you turn your connection off after the map has loaded, then try and zoom in on areas nowhere near the desired location then there seems to be an awful lot of detail still available.
For those journerying here in 2014+ (iOS8 and up)
I am running into this problem on iOS 7+ trying to support older devices (think Ipad 2 with 512MB).
My solution is to disable Zoom as it easily takes the most memory.
long mem = [NSProcessInfo processInfo].physicalMemory;
if(mem < _memory_threshold){
self.MapView.zoomEnabled = NO;
}
I have tried everything from switching map types, to deallocating the map, setting the delegate to nil, removing all overlays, annotations etc.
None of that works on iOS7+. In fact, most of these fixes cause jumps in memory, as MKMapView seems to leak and never properly dealloc (I have verified through sub-classing that I see dealloc hit).
This sucks, but all I have came up with so far is disabling map features (zoom, scroll, user interactions) as a means to limit the atrocious amount of memory MKMapView takes. This has resulted in my App at the very least being semi-stable on older devices.
Not sure about the consequences.
How ever setting map to 'nil' whenever view disappears, helped me to reduce memory usage from ~250MB to ~50-60MB.
-(void)viewDidDisappear:(BOOL)animated
{
self.map = nil;
}
Only following lines are enough to resolve the memory issue:
For Objective-C:
- (void) applyMapViewMemoryFix {
[self.mkMapView removeFromSuperview];
self.mkMapView = nil;}
For Swift 3.0:
func applyMapViewMemoryFix() {
mapView.removeFromSuperview()
self.mapView = nil
}
来源:https://stackoverflow.com/questions/12641658/ios6-mkmapview-using-a-ton-of-memory-to-the-point-of-crashing-the-app-anyone-e