如何释放即将返回的变量?

Win*_*hen 1 iphone objective-c

当我点击Xcode中Build菜单上的"build and analyze"按钮时,我偶然发现了一个问题.分析建议我发布一个我希望以后返回的变量.代码如下:

- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation{

     //I do some other thing here

     MKPinAnnotationView *annView=
        [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"addressLocation"];

     //I do some other thing here

     return annView;
}
Run Code Online (Sandbox Code Playgroud)

我可以释放annView并返回它而不会造成任何问题吗?

Chu*_*uck 6

这正是自动释放的目的.该方法应该自动释放它.

如果你不清楚这类事情,我建议阅读内存管理指南.它非常简短,很好地解释了所有这些.一旦你理解了这个指南,你就再也不必怀疑了.