Capturing self strongly in this block is likely to lead to retain cycle的问题
来源:互联网 发布:java protect 编辑:程序博客网 时间:2024/05/29 04:02
今天在写tableview的刷新的问题的时候遇到了上面的警告,搜了一下大概是因为block会对其调用的对象进行retain一次,防止其调用的对象提前释放,但这样就可能循环引用,就是A持有B,B也持有A,导致这两个对象释放不了,形成内存泄漏。
搜了一下,解决的办法是用 __block ViewController *blockSelf = self;来代替self。当方法执行完之后将blockSelf置为nil。
具体的代码如下:
有问题的代码:
[self.tableView addLegendFooterWithRefreshingBlock:^{ [self loadMoreData]; }];修改之后的代码:
__block WgcxController *blockFooter = self; [self.tableView addLegendFooterWithRefreshingBlock:^{ [blockFooter loadMoreData]; blockFooter = nil; }];
这是比较简单的处理办法,比较详细的讲解可以看两外一篇博客:http://blog.csdn.net/lvxiangan/article/details/50728577
0 0
- Capturing self strongly in this block is likely to lead to 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 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 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 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]
- 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]
- 对if判断始终怀疑态度
- Java设计模式之--模板方法模式(Template Method)
- 获取App Sotre中应用的详情
- 4.0 gridlayout
- sql之left join、right join、inner join的区别
- Capturing self strongly in this block is likely to lead to retain cycle的问题
- 01——vue-cli项目的构建
- Java 使用 jacob 将微软office中 word excel ppt 转成pdf
- RTMP规范简单分析
- Curl windows下载地址
- 《Spring In Action》 读书笔记(4) -- SpEL表达式的简单应用
- 空间复杂度
- umeditor使用小记
- leetcode 28. Implement strStr()