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.
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.
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+.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With