Is it necessary to create an autorelease pool under ARC in GCD?

前端 未结 2 1826
孤独总比滥情好
孤独总比滥情好 2020-12-16 05:50

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:



        
相关标签:
2条回答
  • 2020-12-16 06:10

    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.

    0 讨论(0)
  • 2020-12-16 06:30

    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

    0 讨论(0)
提交回复
热议问题