Tornado and Grand Central Dispatch: a quick look
Posted Sep 18, 2009 10:39 UTC (Fri) by
madcoder (subscriber, #30027)
In reply to:
Tornado and Grand Central Dispatch: a quick look by wahern
Parent article:
Tornado and Grand Central Dispatch: a quick look
What I'm still unclear of is how the run-time handles the
collection of __block-storage objects. It uses some sort of reference
counting on the Block objects, and the __block-storage objects are
referenced by the Block, presumably. But how it manages to decrement the
reference count, I'm not sure of. It might not do it at all, so that in
order for a Block to remain valid outside of the scope it was defined in
you have to use the API, i.e. Block_copy, etc.
Well, there is a Block_release() function for that. And actually, wrt
__block variables, it stores a reference (pointer) to the variable on stack
until you do your first Block_copy, then (if that happens) it moves the
__block variable to the heap, alongside the copied block. IOW the __block
variable address may change between two runs of the same block, that's why
__block is incompatible with static.
(
Log in to post comments)