这在ARC中是如何工作的

时间:2011-12-01 09:46:00

标签: iphone ios sdk automatic-ref-counting

-(void)add
{
    Myview *optionV =[[Myview alloc] initWithFrame:CGRectMake(80,80, 590, 25)];
    [interactiveView addSubview:optionV];

   //interactiveView is UIView added from the nib and has an IBoutlet.
}

现在如果正在调用add方法10次。如何管理内存。为Myview创建@property的最佳方法是什么?

1 个答案:

答案 0 :(得分:4)

ARC在编译时添加了一个简单的版本,因此您的代码将以这种方式重写:

-(void)add
{
    Myview *optionV =[[Myview alloc] initWithFrame:CGRectMake(80,80, 590, 25)];
    [interactiveView addSubview:optionV];
    [optionV release]; //Will be added when compiled, Don't add it your self.
}