Recursive Block Retain Cycles

前端 未结 6 1002
心在旅途
心在旅途 2020-12-13 04:44

Will this lead to any sort of retain cycle? Is it safe to use?

__block void (^myBlock)(int) = [^void (int i)
{
    if (i == 0)
        return;

    NSLog(@\"         


        
6条回答
  •  北荒
    北荒 (楼主)
    2020-12-13 05:40

    No, that will not cause a retain cycle. The __block keyword tells the block to not copy myBlock, which would have occurred before assignment causing the application to crash. If this is not ARC the only thing you will need to do is release myBlock after you call myBlock(10).

提交回复
热议问题