[iOS 源代码分享] MLeaksFinder 可帮助您在开发时查找您的 iOS 应用程序中的内存泄漏 - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
newkengsir
V2EX    iOS

[iOS 源代码分享] MLeaksFinder 可帮助您在开发时查找您的 iOS 应用程序中的内存泄漏

  •  
  •   newkengsir 2016-12-08 09:43:59 +08:00 3258 次点击
    这是一个创建于 3232 天前的主题,其中的信息可能已经有所发展或是发生改变。

    项目介绍地址: http://www.code4app.com/forum.php?mod=viewthread&tid=11844&extra=page%3D4

    ##MLeaksFinder

    MLeaksFinder helps you find memory leaks in your iOS apps at develop time. It can automatically find leaks in UIView and UIViewController objects, present an alert with the leaked object in its View-ViewController stack when leaks happening. More over, it can try to find a retain cycle for the leaked object using FBRetainCycleDetector. Besides finding leaks in UIView and UIViewController objects, developers can extend it to find leaks in other kinds of objects.

    MLeaksFinder 可帮助您在开发时查找您的 iOS 应用程序中的内存泄漏。 它可以自动查找 UIView 和 UIViewController 对象中的泄漏,当泄漏发生时,在其 View-ViewController 堆栈中显示泄漏对象的警报。 更多,它可以尝试使用 FBRetainCycleDetector 找到泄漏对象的保留周期。 除了在 UIView 和 UIViewController 对象中查找泄漏,开发人员可以扩展它以查找其他类型对象中的泄漏。

    Communication

    QQ group: 482121244

    Installation

    pod 'MLeaksFinder' 

    MLeaksFinder comes into effect after pod install, there is no need to add any code nor to import any header file.

    MLeaksFinder 在`pod install'之后生效,不需要添加任何代码或导入任何头文件。

    Usage

    MLeaksFinder can automatically find leaks in UIView and UIViewController objects. When leaks happening, it will present an alert with the leaked object in its View-ViewController stack.

    MLeaksFinder 可以自动查找 UIView 和 UIViewController 对象中的泄漏。 当泄漏发生时,它将在其 View-ViewController 堆栈中提供泄漏对象的警报。

    Memory Leak ( MyTableViewController, UITableView, UITableViewWrapperView, MyTableViewCell ) 

    For the above example, we are sure that objects of MyTableViewController, UITableView, UITableViewWrapperView are deallocated successfully, but not the objects of MyTableViewCell.

    MLeaksFinder can also try to find a retain cycle for the leaked object using FBRetainCycleDetector.

    对于上面的例子,我们确信“ MyTableViewController ”,“ UITableView ”,“ UITableViewWrapperView ”的对象被成功解除分配,但不是“ MyTableViewCell ”的对象。

    MLeaksFinder 也可以尝试使用 FBRetainCycleDetector 查找泄漏对象的保留循环。

    Retain Cycle ( "-> MyTableViewCell ", "-> _callback -> __NSMallocBlock__ " ) 

    With the output, we know that the object of MyTableViewCell has a __strong instance variable named _callback, which is of type __NSMallocBlock__. And _callback also has a __strong reference back to MyTableViewCell.

    使用输出,我们知道MyTableViewCell的对象有一个名为_callback__strong实例变量,它的类型为__NSMallocBlock__。 和_callback也有一个__strong引用返回MyTableViewCell

    Mute Assertion

    If your class is designed as singleton or for some reason objects of your class should not be dealloced, override - (BOOL)willDealloc in your class by returning NO.

    如果你的类被设计为单例,或者由于某些原因你的类的对象不应该被释放,在你的类中重写- ( BOOL ) willDealloc,返回 NO 。

    - (BOOL)willDealloc { return NO; } 

    Find Leaks in Other Objects

    MLeaksFinder finds leaks in UIView and UIViewController objects by default. However, you can extend it to find leaks in the whole object graph rooted at a UIViewController object.

    默认情况下, MLeaksFinder 在 UIView 和 UIViewController 对象中找到泄漏。 但是,您可以扩展它以在基于 UIViewController 对象的整个对象图中查找泄漏。

    - (BOOL)willDealloc { if (![super willDealloc]) { return NO; } MLCheck(self.viewModel); return YES; } 
    1 条回复    2016-12-08 17:34:58 +08:00
    HuangLibo
        1
    HuangLibo  
       2016-12-08 17:34:58 +08:00
    这个确实很好用,可以自动检测 vc 和 view 的循环引用,推荐!
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     2970 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 23ms UTC 14:12 PVG 22:12 LAX 07:12 JFK 10:12
    Do have faith in what you're doing.
    ubao snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86