/BlockLeaksKiller

快速定位Block循环引用所处位置

Primary LanguageObjective-CMIT LicenseMIT

BlockLeaksKiller

CI Status Version License Platform

新增两个宏,从编译期间避免block的循环引用

#define ZbWeakBlock(obj, block) ({__weak typeof(obj) weak##obj = obj; __weak typeof(weak##obj) obj = weak##obj; block;})

#define ZbWeakSelfBlock(block) ZbWeakBlock(self, block)

self.block = ZbWeakSelfBlock(^{
    NSLog(@"访问self也不会循环引用:%@ - %@", self, weakself);
});
self.block();

Example

以demo为例:

当发生内存泄漏时,会有弹窗提示

这时请看控制台的输出:

复制内存泄漏对象地址:

打开Xcode内存图功能:

粘贴内存泄漏对象地址进行查找过滤:

鼠标右键箭头所指向的block->点击Print Description:

查看控制台的输出:

复制红线命令,粘贴至lldb:

红框部分就是block导致循环引用的代码定义处,请自行跳转代码进行修复.

Requirements

Installation

BlockLeaksKiller is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'BlockLeaksKiller'

Author

wsong, 835151791@qq.com

License

BlockLeaksKiller is available under the MIT license. See the LICENSE file for more info.