MKMapView memory leak in iPhone application

I am working on an iPhone application that uses MKMapView and shows userlocation. I get memory leaks where a leaked NSCFArray object of size 128 bytes, GeneralBlock-16, GenralBlock-8, when the MKMapView property of showUserLocation is showUserLocation to TRUE. If set to NO, I do not receive this leak. Can anyone suggest what could be a possible reason for this. Is this an error in the MKMapView class or am I using MKMapView . Can someone tell me what is the best way to use MKMapView and show userLocatio n as well.

Thanks and Regards, Priyanka Aggarwal

+3
memory-leaks iphone
source share
3 answers

I have the same problem. Sounds like an error in MKMapView for me. Come to mind:

  • Create your own annotation for the current position.
  • Do not destroy or recreate the view, so you only get a leak.
  • Unplug it.

Fortunately for me, I can turn it off without any significant loss of function.

+2
source share

I fixed a similar problem by auto-implementing annotationView objects. In addition, MKUserLocation is an annotation object, so checking your own annotation objects (or checking to see if MKUserLocation is an annotation object) and returning zero for other annotation objects (or MKUserLocation) will tell the map set to use MKUserLocation by default. Enabling these checks may stop your leak. See below:

 - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation { static NSString *placemarkIdentifier = @"placemark_identifier"; if ([annotation isKindOfClass:[MyPlaceMark class]]) { MKAnnotationView *annotationView = [mapView dequeueReusableAnnotationViewWithIdentifier:placemarkIdentifier]; if (annotationView == nil) { annotationView = [[[MyPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:placemarkIdentifier] autorelease]; } else { annotationView.annotation = annotation; } return annotationView; } return nil; } 

MKUserLocation class class reference

0
source share

For what it is, there are similar questions:

  • https://stackoverflow.com/questions/5935243/mkmapview-rame-et-fuite-memoire-apple
  • MKMapView is leaking
  • Is it possible to release the memory used by MKMapView like?
-one
source share

All Articles