4

Analyzer 报告以下代码存在潜在的内存泄漏。任何人都可以对此有所了解吗?我正在释放已分配的注释。

  -(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

2 回答 2

7

您在返回后释放,因此永远不会被调用。另请注意,地图视图会在您添加注释时保留它。

于 2012-05-24T15:39:37.490 回答
5

改变

return annotation;
[annotation release];

return [annotation autorelease];
于 2012-05-24T15:40:21.287 回答