【发布时间】:2011-02-05 14:59:31
【问题描述】:
你好,我不完全理解 obj-C 中的 autorelease 函数调用。
@interface A{
id obj;
}
@implementation A
-(void)myMethod;
{
obj = [BaseObj newObj]; //where newObj is a method like :[[[BaseObj alloc]init]autorelease];
}
-(void)anotherMehtod;
{
[obj someMeth]; //this sometimes gives me EXC_BAD_ACCESS
}
@end
所以为了解决这个问题,我设置了一个保留。现在如果我保留它,我需要手动释放它吗?
【问题讨论】:
-
附注:Cocoa 中的规则是,如果方法名称以
new、copy、retain或alloc开头,调用者必须发送release或@ 987654327@ 来平衡它。所以名为newObj的方法不应该自动释放自己的结果。