質問

For example if you create your own GCD queue:

self.renderQueue = dispatch_queue_create("com.test.queue", DISPATCH_QUEUE_SERIAL);

Do you have to create an autorelease pool in every block submitted to that queue, using:

@autoreleasepool {

}

?

Or does ARC create it for you? What happens if you don't specify autoreleasepool in your custom queues?

役に立ちましたか?

解決

It depends on your usage of autoreleased objects.

Every GCD thread has an outermost autorelease pool, but that pool is drained at a time you cannot control directly (currently the drain occurs when the thread becomes idle, just before it parks itself in the kernel awaiting reuse or reaping).

If your process keeps GCD threads active for long periods of time and/or if you create a large number of autoreleased objects (or very large autoreleased objects) in your blocks, you may wish to create a pool in your blocks to ensure the resources occupied by those objects are freed up earlier.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top