Analyzer reports that the following code leak
-
10-06-2021 - |
Question
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];
}
Solution
change
return annotation;
[annotation release];
to
return [annotation autorelease];
OTHER TIPS
You are releasing after the return, so never gets called. Also note that the map view retains the annotation when you add it.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow