【发布时间】:2011-07-05 11:55:48
【问题描述】:
如何在方法具有返回类型的方法中设置 NSAutoreleasePool? 有没有办法做到这一点? 喜欢下面的方法:
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation, AddressAnnotation>) annotation;
或者在一个被覆盖的方法中,比如:
- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated;
我可以在 main.m 文件中看到如下:
int main(int argc, char *argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
//Do anything here
int retVal = UIApplicationMain(argc, argv, nil, nil);
[pool release];
return retVal;
}
所以应该是这样的?
【问题讨论】:
-
呃。返回值没有什么特别之处。创建一个自动释放池,并在完成后释放它。如果有任何对象需要在池之外存在,请确保您拥有它们。
标签: iphone objective-c ios nsautoreleasepool