I am using MKMapView in Objective-C. App is taking 45MB memory, but when MKMapView appears memory usage increases up to 110 MB. This is not good iPhone 4 and iPhone 4S.
Please suggest me code structure for optimize memory.
I am using MKMapView in Objective-C. App is taking 45MB memory, but when MKMapView appears memory usage increases up to 110 MB. This is not good iPhone 4 and iPhone 4S.
Please suggest me code structure for optimize memory.
Well working with MKMapKit need to be careful about Memory Management. Especially if you are using UITabbarController and setting MapView in any of the view controller.
If you need to use MKMapKit in your application i would recommend you to initialise MapView in viewWillAppear and remove from Superview in viewDidDisappear. Also you need to remove it's delegate mapView.delegate = nil and make MapView = nil before removing from Superview.
Objective-C
- (void)viewDidDisappear:(BOOL)animated { [super viewDidDisappear:animated]; mapView.delegate = nil; [mapView removeFromSuperview]; mapView = nil; } swift
override func viewDidDisappear(animated: Bool) { super.viewDidDisappear(animated) mapView.delegate = nil mapView.removeFromSuperview() mapView = nil } By doing this all you memory occupied by map will be free.
Please do not add MapView in your ViewController in Storyboard or xib. Create MapView Programmatically.
Hope it helps you with Memory Management with MKMapKit.
Are you using iOS 9 ?
I do this and I have no memory issues with my maps - in iOS 8 and below this was an issue and there are many threads on this topic.
So if you are in iOS 9, do this and see if it helps.
override func viewDidDisappear(animated: Bool) { super.viewDidDisappear(animated) mapView.removeFromSuperview() }