ios - 是否需要在GCD中的ARC下创建一个autorelease pool?

标签 ios memory-management concurrency automatic-ref-counting grand-central-dispatch

我有一个 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/

相关文章:

ios - 如何控制 tableViewCell 中的 AVPlayer(通过 slider 和搜索播放、暂停、进度)?

memory - 分页/页面错误处理程序 - 如何使用虚拟地址查找磁盘上的特定内容

php - 我如何判断我的 php 脚本用完了多少内存/资源?

java - CompareAndExchange 与 CompareAndExchangeAcquire 之间有什么区别

java - wait()和notify()方法,总是发生IllegalMonitorStateException并告诉我当前线程不是Owner,为什么?

ios - Facebook原生广告无法点击,无 react

ios - fillMode 为 kCAFillModeBackwards 有什么影响?

java - Java中AtomicXXX上lazySet的使用

ios - 在 SpriteKit 中重置场景

c++ - EasyBMP c++ 的 RGBApixel 内存问题