in Technology by (1.8m points)

What are NSAutoreleasePool? When to use them?

1 Answer

0 votes
by (1.8m points)

The NSAutoreleasePool class is used to support Cocoa’s reference-counted memory management system. An autorelease pool stores objects that are sent a release message when the pool itself is drained.

Also, If you use Automatic Reference Counting (ARC), you cannot use autorelease pools directly. Instead, you use @autoreleasepool blocks. For example, in place of:

NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

// Code benefitting from a local autorelease pool.

[pool release];

You would write:



// Code benefitting from a local autorelease pool.


@autoreleasepool blocks are more efficient than using an instance of NSAutoreleasePool directly; you can also use them even if you do not use ARC.

Related questions

0 votes
asked Dec 30, 2021 in Education by JackTerrance (1.8m points)