Why does Xcode 4.2 use @autoreleasepool in main.m instead of NSAutoreleasePool?

喜你入骨 提交于 2019-11-30 04:57:28
Ignacio Inglese

The first one is using ARC, which is implemented in iOS5 and above to handle memory management for you.

On the second one, you're managing your own memory and creating an autorelease pool to handle every autorelease that happens inside your main function.

So after reading a bit on what's new on Obj-C with iOS5 it appears that the:

@autoreleasepool {
    //some code
}

works the same as

NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
// some code
[pool release];

with the difference that the last one would throw an error on ARC.

EDIT:

The first one is using ARC or not.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!