我已经在我的课如何处理内存为只读属性
@property (nonatomic, retain, readonly) NSMutableArray *children;
之一下列财产,我有以下的方法来分配内存这个属性。
- (NSMutableArray *)children {
if (!children) {
children = [[NSMutableArray alloc] initWithCapacity:1];
}
return children;
}
当我在xcode中运行profiler时,它显示我在上面的方法中有内存泄漏。在这种情况下,我对释放记忆感到困惑。 如果我按照以下方式使用autorelase,可以吗?
children = [[[NSMutableArray alloc] initWithCapacity:1] autorelease];
有人可以帮我解决这个问题。
如果您在类的''init'“或”'viewDidLoad'“方法(后者,如果它是视图控制器)中创建”children“,内存泄漏警告会消失吗? –
你在用ARC编译吗? (我假设不是,但只是为了......) – Sean
@Sean Im不使用ARC。 – nath