@autoreleasepool Blocks

You’ve seen in every example in this book so far how the compiler generates an @autoreleasepool directive inside your main routine. This directive encloses a block of statements that define an autoreleasepool context. Any objects created in that context that are autoreleased will be destroyed by default at the end of that autoreleasepool block (unless the compiler has taken care to guarantee their survival past the end of the block).

If your program generates a lot of temporary objects (which can easily happen when executing code inside a loop), you might want to create multiple autoreleasepool blocks in your program. For example, the following code fragment illustrates how you can set up autoreleasepool blocks to manage ...

Get Programming in Objective-C, Sixth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.