Analyzer reports that the following code has a potential memory leak. Can anyone shed some light on this? I'm releasing the annotation that's been allocated.
-(AddressAnnotation *)addAdress:(NSString*)placeTitle SubTitle:(NSString*)placeSubTitle Coordinate:(CLLocationCoordinate2D)coord withId:(NSInteger) placeId{
AddressAnnotation *annotation = [[AddressAnnotation alloc] initWithCoordinate:coord];
annotation.placeTitle = placeTitle;
annotation.placeSubTitle = placeSubTitle;
annotation.museumId = placeId;
[mapView addAnnotation:annotation];
return annotation;
[annotation release];
}
You are releasing after the return, so never gets called. Also note that the map view retains the annotation when you add it.
change
return annotation;
[annotation release];
to
return [annotation autorelease];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With