Watch out the MapKitView

Found a location service problem in one of the app I’ve built for my client.

The problem, even after calling locationManager stopUpdatingLocation, the location service indicator still shows app is using location service!

Debug around, then found out it might be caused by the MapkitView in the details view. That details view has been already pop out from the navigation stack, the some how the MapKitView is still stay in memory sucking the location service!

Using Instrument tool to debug this, it proofs that even after the details view dismissed, the process list still shows the MapKit and geo services.

Great! Now try to do the clean up.

Tried self.mapView.delegate = nil; and self.mapView = nil; in viewWillDisapper, didn’t help.

Finally the trick is to call [self.mapView removeFromSuperView];

Some other posts pointed out the good practice is to create MapKitView on demand instead of dragging to view. Same solution.

Here is the proper code to clean up mapview:

[self.mapView removeFromSuperView]; //very important to completely clean up memory used by location service 
self.mapView.delegate = nil;
self.mapView = nil;

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s