Possible error in MKMapView

If I create a ViewController with a map view, and this is the only code that 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 an error message:

 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 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, I will not 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 on the map, where as, (-90, -180) is not displayed. That is, I need to pan the map to display the coordinate (-90, -180).

Has anyone experienced this error before or even better knows how to fix it?

+6
source share
1 answer

After some testing, I am convinced that this is a bug in MKMapView. I worked on this, adding only annotations that are in the visible area. More work, but at least it doesn't crash my application :)

+5
source

Source: https://habr.com/ru/post/893433/


All Articles