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

后端 未结 1 500
滥情空心
滥情空心 2020-12-29 08:24

I\'ve noticed that there is a different way in Xcode 4.2 to start the main function:

int main(int argc, char *argv[])
{
    @autoreleasepool {
        return         


        
相关标签:
1条回答
  • 2020-12-29 08:36

    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.

    0 讨论(0)
提交回复
热议问题