I’m using the following code to make a pin for annotation:
- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation
{
MKPinAnnotationView *annView=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"currentloc"];
annView.pinColor = MKPinAnnotationColorGreen;
annView.animatesDrop=TRUE;
annView.canShowCallout = YES;
annView.calloutOffset = CGPointMake(-5, 5);
return annView;
}
Everything works perfectly, however Analyze in XCode shows memory leak in this code. In fact, I see it too cos I allocated object and then did not released it.
How can I avoid memory leak here?
You didn’t wrote, but I think analyzer tells you what it leaks here:
Thats because you need autorelease item:
UPDATE
Also you don’t reuse created annotations, try do this: