The analyzer reports that the next code leak

The analyzer reports that the following code has a potential memory leak. Can someone shed some light on this? I am releasing an annotation that has been highlighted.

-(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]; } 
+4
source share
2 answers

change

 return annotation; [annotation release]; 

to

 return [annotation autorelease]; 
+5
source

You are freed upon return, therefore you are never called. Also note that the map display retains the annotation when it is added.

+7
source

Source: https://habr.com/ru/post/1414183/


All Articles