@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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access