我有一些代码基本上可以归结为:
-(void)doSomethingWithBlock:(BlockTypedef)block
{
[Foo doSomethingElseWithBlock:^() {
block();
}];
}
Foo doSomethingElseWithBlock:
在它收到的 block 上调用 Block_copy
和 Block_release
。这在外部范围是否也是必要的,或者内部 Block_copy
会处理这个吗?
最佳答案
我引用 Blocks Programming Topics Apple 开发人员文档网站上的指南:
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.
关于objective-c - Block_copy 是递归的吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6420656/