gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 04:07:56 26 4
gpt4 key购买 nike

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

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com