NSAutoreleasePool

From iPhone Development Wiki
Revision as of 17:25, 21 September 2009 by KennyTM~ (talk | contribs) (the argument of NSPushAutoreleasePool is an unsigned integer, not a pointer. See -[NSAutoreleasePool initWithCapacity:].)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

The NSAutoreleasePool class is a thin wrapper around the NSPushAutoreleasePool and NSPopAutoreleasePool functions.

#ifdef __cplusplus
extern "C" {
#endif
void *NSPushAutoreleasePool(NSUInteger capacity);
void NSPopAutoreleasePool(void* token);
#ifdef __cplusplus
}
#endif

Example:

static void MyMethod()
{
    void *pool = NSPushAutoreleasePool(0);
    [[[NSObject alloc] init] autorelease];
    NSPopAutoreleasePool(pool);
}

The "capacity" argument of NSPushAutoreleasePool only serves as a hint. It is unused in the current implementation.