Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Analyzer reports that the following code leak

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];
    }
like image 411
hanumanDev Avatar asked Dec 16 '22 23:12

hanumanDev


2 Answers

You are releasing after the return, so never gets called. Also note that the map view retains the annotation when you add it.

like image 183
Alladinian Avatar answered Dec 27 '22 06:12

Alladinian


change

return annotation;
[annotation release];

to

return [annotation autorelease];
like image 44
coneybeare Avatar answered Dec 27 '22 06:12

coneybeare