我注意到苹果文档中提到需要避免强引用循环,当使用self时。
在示例中,该块是self的一个属性。
但是如果我将块作为dispatch_async语句中的局部变量放置呢?
在这种情况下,即使直接调用self的方法,也不会创建保留循环,对吧?
以下代码是否需要生成weakSelf,见此文章?
// your code
__weak typeof(self) weakSelf = self;
dispatch_async(dispatch_get_main_queue(), ^{
__strong typeof(weakSelf) strongSelf = weakSelf;
if (strongSelf) {
[strongSelf doThis];
[strongSelf doThat];
[Manager.sharedInstance updateSuccessCount];
}
});
// more code