我通過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