Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

@autoreleasepool without ARC?

People also ask

What is Autorelease pool?

An autorelease pool stores objects that are sent a release message when the pool itself is drained. Important. If you use Automatic Reference Counting (ARC), you cannot use autorelease pools directly. Instead, you use @autoreleasepool blocks.

What is the Autorelease pool in Swift?

The autoreleasepool allows you to explicitly manage when autorelease objects are deallocated in Swift, just like you were able to in Objective-C. Note: When dealing with Swift native objects, you generally will not receive autorelease objects.

What is Objective-C Arc?

Automatic Reference Counting (ARC) is a memory management option for Objective-C provided by the Clang compiler. When compiling Objective-C code with ARC enabled, the compiler will effectively retain, release, or autorelease where appropriate to ensure the object's lifetime extends through, at least, its last use.


From http://clang.llvm.org/docs/AutomaticReferenceCounting.html#autoreleasepool:

@autoreleasepool may be used in non-ARC translation units, with equivalent semantics.

and Greg Parker says [1] [2]:

LLVM 3.0's @autoreleasepool { ... } is much faster than NSAutoreleasePool if your deployment target is new enough. No ARC required. (…) always works, but it's faster with deployment target of OS X 10.7 or iOS 5.0.

So you may use @autoreleasepool regardless of ARC, and it’ll be faster than NSAutoreleasePool on OS X v10.7+ and iOS 5.0+.