我通过autoreleasing我的annotationView对象修复了一个类似的问题。此外,MKUserLocation是一个注释对象,因此检查您自己的注释对象(或检查注释对象是否为MKUserLocation),并返回其他注释对象(或MKUserLocation)的nil将告诉地图工具包使用默认的MKUserLocation对象。把这些检查到位可以阻止你的泄漏。请看下图:
- (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 reference