Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Possible bug in MKMapView

Tags:

ios

iphone

If I create a ViewController with a map view and this is the only code I add to viewDidLoad:

MKPointAnnotation* annotation = [[MKPointAnnotation alloc] init];
annotation.coordinate = CLLocationCoordinate2DMake(-90, -180);
[self.mapView addAnnotation:annotation];
[self.mapView removeAnnotation:annotation];
[annotation release];

I get the error:

An instance 0xa126fa0 of class MKPointAnnotation was deallocated while key value observers were still registered with it. Observation info was leaked, and may even become mistakenly attached to some other object. Set a breakpoint on NSKVODeallocateBreak to stop here in the debugger. Here's the current observation info:
<NSKeyValueObservationInfo 0xa127df0> (
<NSKeyValueObservance 0xa127c90: Observer: 0xa11c530, Key path: coordinate, Options: <New: NO, Old: NO, Prior: YES> Context: 0x0, Property: 0xa127640>

If I change the code to this then I don't get any errors:

MKPointAnnotation* annotation = [[MKPointAnnotation alloc] init];
annotation.coordinate = CLLocationCoordinate2DMake(0, 0);
[self.mapView addAnnotation:annotation];
[self.mapView removeAnnotation:annotation];
[annotation release];

The only difference is that (0,0) is visible in the map, where as, (-90, -180) is out of view. That is, I need to pan the map to bring coordinate (-90, -180) into view.

Anyone experienced this error before or even better know how to fix it?

like image 870
Michael Del Borrello Avatar asked Jul 24 '11 04:07

Michael Del Borrello


1 Answers

After some more testing I'm convinced it is a bug in MKMapView. I worked around it by only adding annotations that are in the visible region. More work but at least it doesn't crash my app :)

like image 164
Michael Del Borrello Avatar answered Sep 30 '22 10:09

Michael Del Borrello