Block_copy是递归的吗? [英] Is Block_copy recursive?
问题描述
我有一些基本上归结为这样的代码:
I have some code that essentially boils down to this:
-(void)doSomethingWithBlock:(BlockTypedef)block
{
[Foo doSomethingElseWithBlock:^() {
block();
}];
}
Foo doSomethingElseWithBlock:
在它接收的块上调用 Block_copy
和 Block_release
。这在外部范围也是必要的,或者内部 Block_copy
处理这个?
Foo doSomethingElseWithBlock:
calls Block_copy
and Block_release
on the block that it receives. Is this also necessary at the outer scope, or will the inner Block_copy
handle this?
推荐答案
我引用阻止编程主题指南在Apple的开发者文档网站:
I quote the Blocks Programming Topics guide on Apple's developer documentation site:
复制块时,任何如果需要,则复制对该块内的其它块的引用 - 可以复制(从顶部)整个树。
When you copy a block, any references to other blocks from within that block are copied if necessary—an entire tree may be copied (from the top). If you have block variables and you reference a block from within the block, that block will be copied.
当你复制一个基于堆栈的块时,你会得到一个新的块。但是,如果复制基于堆的块,则只需增加该块的保留计数,并将其返回为复制函数或方法的返回值。
When you copy a stack-based block, you get a new block. If you copy a heap-based block, however, you simply increment the retain count of that block and get it back as the returned value of the copy function or method.
这篇关于Block_copy是递归的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!