ios - 我想知道 capturing self strongly in this block 警告造成的后果有哪些
PHPz
PHPz 2017-04-17 17:50:04
0
3
635

项目上线了 但是一直有一个BUG修复不了 似乎那个crash崩溃地址每次都不同 所以很难定位类似libobjc.A.dylib objc_msgSend (sendMessage:)这样的错误

检查代码 发现有这么一个在ARC模式下的警告
capturing self strongly in this block is likely to lead to a retain cycle 这是一个block导致的循环引用
这个警告会导致什么问题 会导致直接崩溃吗 我想知道跟上面的崩溃有联系吗

PHPz
PHPz

学习是最好的投资!

reply all(3)
Ty80

There are some differences between the two.
objc_msgSend (sendMessage:) is because the method is called on the released object.

capturing self strongly in this block is likely to lead to a retain cycle
which will cause the created object to not be released.
For example, every time you enter a vc, it is newly created. The block in vc has a strong reference to self.
This will cause this vc to be unable to be released. A new vc will be created every time you enter, and the old vc will still exist. Finally, the application will be cleared by the system because it takes up too much memory.

Ty80

It is possible, but it is unlikely, but the circular reference must be removed.

左手右手慢动作

This will cause a memory leak, but whether it will cause a crash depends on the situation.
For example, a certain VC registered a notification, but due to a circular reference, it was not released correctly. After that, the notification was posted elsewhere, then the VC will perform the corresponding operation. Maybe it operates The thing has been released, then it may crash.
It is difficult to locate errors like your libobjc.A.dylib objc_msgSend (sendMessage:). You should see if there is other information, such as something similar to this:

You can try using Fabric.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template