我有一个 CAEAGLLayer 的运行循环方法,它使用 GCD 来序列化对共享 ivar 的访问。
我目前的绘图代码是这样构造的:
- (void)draw {
dispatch_sync(serialDrawingQueue, ^{
@autoreleasepool {
[self drawingStart];
[spriteA draw];
[spriteB draw];
[self drawingEnd];
}
});
}
draw
方法由 CADisplayLink 调用。
当我使用 GCD block 时,@autoreleasepool
是否必需?
最佳答案
来自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.
关于ios - 是否需要在GCD中的ARC下创建一个autorelease pool?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12586977/