-(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的最佳方法是什么?

最佳答案

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.
}

10-08 07:07