我在一些示例代碼中看到autorelease
被使用。在需要時我不熟悉這些實例。例如,如果我創建一個註釋對象使用點語法設置retain屬性時使用autorelease?
頭文件
@interface someViewController: UIViewController
{
Annotation *annotation;
}
@property (nonatomic, retain) Annotation *annotation;
@end
實現文件
@implementation someViewController
@synthesize annotation
@end
問:這是不是正確的做法,如果我在這樣的實現文件初始化我的註釋對象?
self.annotation = [[Annotation alloc] initWithCoordinate:location];
我需要爲此設置autorelease嗎?或者我可以按照正常的方式進行操作,並在dealloc方法中添加發布版本?
[自動釋放與釋放(http://stackoverflow.com/questions/4077159/autorelease-vs-release)和可能的複製還有,如果你花時間去閱讀,這將回答這個問題很多很多其他問題他們:[搜索:iPhone保留屬性autorelease](http://stackoverflow.com/search?q=iphone+retain+property+autorelease)這:[發佈/ autorelease混淆](http://stackoverflow.com/questions/ 1121343/release-autorelease-confusion-in-cocoa-for-iphone)可能是最好的之一。 – 2011-05-19 07:45:26