objc中关于自动释放池,有两种语法,一种old-fashioned是:
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
//do something...
[pool release];
那么新的语法是:
@autoreleasepool{
//do something
}
可以明显看出,后者比前者语法要简单,那么新式和旧式的语法有神马区别呢?
apple dev里有清楚的说明:
NSAutoreleasePool class用来支持Cocoa的引用计数内存管理系统。如果你使用ARC,你不能直接使用autoreleasepool,作为替代,你可以使用@autoreleasepool块的语法:
If you use Automatic Reference Counting (ARC), you cannot use autorelease pools directly. Instead, you use @autoreleasepool blocks. For example, in place of:
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
// Code benefitting from a local autorelease pool.
[pool release];
you would write:
@autoreleasepool {
// Code benefitting from a local autorelease pool.
}
但随后文档也说了:@autoreleasepool块的语法更有效率,所以你也可以在不使用ARC的情况下使用该语法。