I have a run loop method for a CAEAGLLayer which uses GCD for serializing access to shared ivars.
My drawing code currently is constructed like this:
From the Apple docs:
If your block creates more than a few Objective-C objects, you might want to enclose parts of your block’s code in an @autorelease block to handle the memory management for those objects. Although GCD dispatch queues have their own autorelease pools, they make no guarantees as to when those pools are drained. If your application is memory constrained, creating your own autorelease pool allows you to free up the memory for autoreleased objects at more regular intervals.
It seems that in iOS10 or higher dispatch queues no longer surround blocks by default in @autoreleasepool
. This is indicated by DISPATCH_QUEUE_SERIAL_WITH_AUTORELEASE_POOL
and DISPATCH_QUEUE_CONCURRENT_WITH_AUTORELEASE_POOL
macros defined in queue.h