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

I noticed that in Xcode 4.2 there is another way to run the main function:

int main(int argc, char *argv[]) { @autoreleasepool { return UIApplicationMain(argc, argv, nil, NSStringFromClass([PlistAppDelegate class])); } } 

and

 int main(int argc, char *argv[]) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; int retVal = UIApplicationMain(argc, argv, nil, nil); [pool release]; return retVal; } 

Does anyone know the difference between the two?

+13
ios xcode nsautoreleasepool autorelease
Jan 03 2018-12-01T00:
source share
1 answer

The first uses ARC, which is implemented in iOS5 and higher to manage memory for you.

In the second, you manage your own memory and create an autoplay pool to handle each auto-advertisement that occurs inside your main function.

So, after reading a little about what's new on Obj-C with iOS5, it seems that:

 @autoreleasepool { //some code } 

works the same way

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

with the difference that the latter will cause an error in the ARC.

EDIT

The first uses ARC or not.

+14
Jan 03 '12 at 15:57
source share



All Articles