Consider this example:
- (void)doSomething {
@autoreleasepool {
if (someCondition) {
/* ... allocate some autoreleased objects here ... */
return;
}
}
}
Previously, with manual NSAutoreleasePools, if we returned early, we needed to call [pool drain]
, otherwise the pool would not be drained.
With the new @autoreleasepool {}
The answer is YES:
When the block is exited normally, whether by fallthrough or directed control flow (such as return or break), the autorelease pool is restored to the saved state, releasing all the objects in it. When the block is exited with an exception, the pool is not drained.
Source: http://clang.llvm.org/docs/AutomaticReferenceCounting.html#autoreleasepool
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