Foo*_*Foo 14 xcode autorelease nsautoreleasepool ios
我注意到在Xcode 4.2中有一种不同的方式来启动main函数:
int main(int argc, char *argv[])
{
@autoreleasepool {
return UIApplicationMain(argc, argv, nil,
NSStringFromClass([PlistAppDelegate class]));
}
}
Run Code Online (Sandbox Code Playgroud)
和
int main(int argc, char *argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, nil);
[pool release];
return retVal;
}
Run Code Online (Sandbox Code Playgroud)
有人知道这两者之间的区别吗?
Ign*_*ese 14
第一个是使用ARC,它在iOS5及更高版本中实现,为您处理内存管理.
在第二个,您正在管理自己的内存并创建自动释放池来处理主函数内发生的每个自动释放.
因此,在阅读了有关iOS5的Obj-C的新内容之后,看来:
@autoreleasepool {
//some code
}
Run Code Online (Sandbox Code Playgroud)
与...一样的工作
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
// some code
[pool release];
Run Code Online (Sandbox Code Playgroud)
区别在于最后一个会在ARC上抛出错误.
编辑:
第一个是否使用ARC.
归档时间: |
|
查看次数: |
10470 次 |
最近记录: |