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:
- (void)draw {
dispatch_sync(serialDrawingQueue, ^{
@autoreleasepool {
[self drawingStart];
[spriteA draw];
[spriteB draw];
[self drawingEnd];
}
});
}
The draw
method is called by a CADisplayLink.
Is the @autoreleasepool
necessary when I use GCD blocks?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With