New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
37 题 block 循环引用问题 #50
Comments
__weak在mrc下可用 |
@HppZ 请注意:__weak是iOS4.2的之后ARC产物。你可以在MRC是使用__weak测试下。会爆警告:'__weak' only applies to Objective-C object or block pointer types; type here is 'int'。而block块内操作的变量会爆红:Variable is not assignable (missing __block type specifier)。 @maquannene __weak修饰符的语义:指定一个引用,该引用不会使引用的对象保持活着状态。 当没有强引用时,弱引用设置为零,指针置空nil。官方文档:https://developer.apple.com/library/content/releasenotes/ObjectiveC/RN-TransitioningToARC/Introduction/Introduction.html#//apple_ref/doc/uid/TP40011226-CH1-SW4 对于楼主的issue第一句话“ARC 下 __weak 可避免循环引用,__block 不行”认同。 |
It waste my 5 minutes to prove my hesitation. In order to prevent I get this rude question to wast my time again, i paste official docs which @HaiTeng-Wang provided:
|
@ChenYilong 既然ARC下__block无法避免循环引用,那为什么不修正答案呢?补充一点,OC高级编程一书中有说__block可以避免循环引用,但前提是要及时的将__block变量置为nii. |
已更正,并在文中附带了该 issue 讨论链接 |
ARC 下 __weak 可避免循环引用,__block 不行。 __block 仅在 MRC 下可解决循环引用的问题,但是会有野指针的问题。
The text was updated successfully, but these errors were encountered: