Re: Cancelling dispatch_after?


On Nov 8, 2017, at 5:54 PM, Quincey Morris <quinceymorris@...> wrote:

I think that should be an “or”: if you assign it to a non-local variable *or* pass it as a parameter.

No, because then blocks would always be copied to the heap, even in common cases where they don’t escape, like calling NSDictionary’s -enumerateKeysAndValues: method. That would make these a lot more expensive.

A block literal passed to a function/method is uncopied, just a direct pointer to a structure in the caller’s stack frame. The called function has to copy the block if it will keep a reference that lasts after it returns. This used to be manual, but ARC does it automatically if you assign the block to an ivar or global.


Join to automatically receive all group messages.