What is an @autoreleasepool in Objective-C?

@autoreleasepool is a new feature of Objective-C 3.0. An example of its usage and the equivalent in previous versions of Objective-C:

  1. @autoreleasepool { 
  2. // Do some cool stuff 

  1. NSAutoreleasePool *pool = [NSAutoreleasePool new]; 
  2. // Do some cool stuff 
  3. [pool drain]; 

Note that the second sample is no longer valid code -- instantiating your own autorelease pool objects is no longer allowed.

The primary reason for this syntactical change is to allow for moving autorelease pools down the stack into the runtime along with retain/release itself -- in previous versions of ObjC/Cocoa, the autorelease functionality was provided by Foundation. La implementación de ARC se hace más fácil por este cambio y parece proporcionar un aumento de rendimiento también.

Para más información ver la sesión "Objective-C Advancements In-Depth" de la WWDC2011, disponible aquí para cualquier persona con una cuenta gratuita de ADC: https://developer.apple.com/videos/wwdc/2011/includes/objective-c-advancements-in-depth.html#objective-c-advancements-in-depth