Capturing 'self' strongly in this block is likely to lead to a retain cycle
来源:互联网 发布:2012服务器端口怎么开 编辑:程序博客网 时间:2024/05/16 09:54
摘自:http://zhidao.baidu.com/link?url=YSVX3-ulNsH1pUQihP6cv67BfJ9qpjtmpFBO89VcArAhPCCAdgf6yhFO881LfEJvuEFfdutzS01Fu8-_d8A_X10PzBuYiqZWjYqxPlMxr_3
block 是代码块的意思。
甲里引用乙,乙里引用甲,就会导致 “retain cycle” -- “形成怪圈”的错误。
网上资料:
解决的办法是 创建一个本地变量 指向 自己(self).
例如:_items 实际上是 self->items,
_block 对象在创建的时候会被retain一次
改成:
__block ViewController *blockSelf = self;
_block = ^{
[blockSelf->_items addObject:@"Hello!"];
};
就可以了。
-------------------
DoSomethingManager *manager = [[DoSomethingManager alloc] init];
manager.complete = ^{
//...complete actions
[manager otherAction];
manager.complete = nil; // Objective-C 用这种方法破坏怪圈。
[manager release];
};
-------------
0 0
- Capturing 'self' strongly in this block is likely to lead to a retain cycle
- capturing self strongly in this block is likely to lead to a retain cycle
- Capturing self strongly in this block is likely to lead to a retain cycle
- Capturing 'self' strongly in this block is likely to lead to a retain cycle
- Capturing 'self' strongly in this block is likely to lead to a retain cycle
- Capturing 'self' strongly in this block is likely to lead to a retain cycle [duplicate]
- Capturing 'self' strongly in this block is likely to lead to a retain cycle
- capturing self strongly in this block is likely to lead to a retain cycle
- Capturing 'self' strongly in this block is likely to lead to a retain cycle
- Capturing 'self' strongly in this block is likely to lead to a retain cycle [duplicate]
- Capturing 'self' strongly in this block is likely to lead to retain cycle 解决方案
- Capturing self strongly in this block is likely to lead to retain cycle解决方案
- Capturing self strongly in this block is likely to lead to retain cycle
- Capturing self strongly in this block is likely to lead to retain cycle的问题
- iOS之Block报错:capturing self strongly in this block is likely to lead to a retain cycle
- iOS之Block报错:capturing self strongly in this block is likely to lead to a retain cycle
- iOS--错误集锦--Capturing 'self' strongly in this block is likely to lead to a retain cycle
- 防止出现 Capturing 'self' strongly in this block is likely to lead to a retain cycle [duplicate]
- 电路设计(二)之串联匹配电阻的应用
- 关于Volatile关键字的一点理解
- bzoj 2115: [Wc2011] Xor (高斯消元求解线性基)
- 对话框的实现
- 基于图像内容的图像检索技术——sift特征
- Capturing 'self' strongly in this block is likely to lead to a retain cycle
- Android手机获取外网ip(by 星空武哥)
- 关于Android Studio导入源码的问题解决
- 打印出所有的“水仙花数”,所谓“水仙花数”是指一个三位数,其各位数字立方和等于该数本身。
- HDFS命令
- jsp form事件和 js 函数不能并行
- 专题二,搜索
- LeetCode——056
- 引导页