Veg*_*gar 0 objective-c autorelease nsstring
在下面的方法中,我不确定为什么释放其中一个数组会导致异常.我能看到的唯一原因是,如果componentsSeparatedByString返回一个自动释放的数组,但我看不出文档中提到它确实存在.
-(void)addRow:(NSString *)stringWithNumbers;
{
NSArray *numbers = [stringWithNumbers componentsSeparatedByString:@" "];
NSMutableArray *row = [[NSMutableArray alloc] initWithCapacity:[numbers count]];
for (NSString *number in numbers) {
Number *n = [[Number alloc] initWithNumber:number];
[row addObject:n];
[n release];
}
[rows addObject:row];
[row release];
// [numbers release]; <-- leads to exception
}
Run Code Online (Sandbox Code Playgroud)
任何人都可以确认阵列是否已自动释放?如果是这样,我怎么知道/为什么我应该知道?
是否可以通过代码检查对象的任何一个实例是否自动释放?
Dav*_*ong 11
是的,因为方法的名称:
newallocretaincopy这通常称为"NARC"规则,并在此处详细说明:http://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/MemoryMgmt/Articles/mmObjectOwnership.html#//apple_ref/doc/UID/20000043-SW1
| 归档时间: |
|
| 查看次数: |
3077 次 |
| 最近记录: |