POSIX callbacks and NSAutoreleasePool with ARC

According to this Apple page , I read that when interacting with Cocoa in a POSIX stream, I have to create an NSAutoreleasePool .

If you create Cocoa calls outside of the main thread application sets - for example, if you create an application only for Foundation or if you disconnect the stream - you need to create your own autoresource pool.

Unfortunately, the use of NSAutoreleasePool prohibited in ARC.

What should I do to ensure that there is always a pool for any ARC code that is auto-implemented?

Thanks!

+4
source share
1 answer

Use @autoreleasepool .

 @autoreleasepool { // make Cocoa calls here } 

This allows the compiler to reason about the lifetime of objects crossing the pool boundary, which is a requirement for ARC. (This is why you cannot use NSAutoreleasePool .) As a bonus, it is also faster.

+5
source

All Articles