17

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 {}

Martijn Thé
  • 4,674
  • 3
  • 29
  • 42

1 Answers1

16

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

Martijn Thé
  • 4,674
  • 3
  • 29
  • 42