【发布时间】:2011-12-18 08:03:28
【问题描述】:
假设我在 A 类中编写了下面的代码:
-(NSArray *) returnListNames {
NSArray *returnList = [NSArray arrayWithArray:myListNames];
return (returnList);
}
在 B 类中,我以这种方式在某个范围内获得该列表:
{
/* Without ARC I would retain the array returned from ClassA
to guarantee its reference like this:
[[myClassA returnListNames] retain]; */
NSArray *myNames = [myClassA returnListNames];
}
考虑到returnList 是使用自动释放方法分配的,我如何保证使用ARC 不会丢失对它的引用(在这种情况下我不能使用retain)?
我必须在myNames 数组上使用[[NSArray alloc] init] 吗?或者我必须在returnList 上使用alloc 而不是自动释放方法?或者我可以只依靠ARC吗?还是有其他解决方案?
【问题讨论】:
标签: objective-c cocoa-touch memory-management ios5 automatic-ref-counting