In Apple's doc I can't find what I can do when I want to capture a CoreFoundation object.
But in Apple's Concurrency Programming Guide. It seems the sample code use some code when dispatch object is not support ARC just like this:
void average_async(int *data, size_t len, dispatch_queue_t queue, void (^block)(int))
{
// Retain the queue provided by the user to make
// sure it does not disappear before the completion
// block can be called.
dispatch_retain(queue);
// Do the work on the default concurrent queue and then
// call the user-provided block with the results.
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
int avg = average(data, len);
dispatch_async(queue, ^{ block(avg);});
// Release the user-provided queue when done
dispatch_release(queue);
});
}
Do I need to use CFObject
like the DispatchObject
before. But if I need to invoke the block many times?
Maybe I can use __attribute__((NSObject))
, but I don't know what will happen!
Does Apple say something about this?