MLeaksFinder Documentation

repository·master·Indexed 26 days ago

https://github.com/tencent/mleaksfinder

A tool for iOS developers to detect memory leaks in UIView and UIViewController objects. It provides visual alerts for leaks and supports custom object graph monitoring via the MLCheck macro. Integration is available via CocoaPods, with optional support for FBRetainCycleDetector for retain cycle detection.

Tokens
386
Snippets
4
Records
5
Agent score
40%

What's inside MLeaksFinder

  1. Enable FBRetainCycleDetector for retain cycle detection

    master

    MLeaksFinder does not include FBRetainCycleDetector by default due to licensing. To use it for finding retain cycles, you must manually add FBRetainCycleDetector to your Podfile and enable the MEMORY_LEAKS_FINDER_RETAIN_CYCLE_ENABLED macro in MLeaksFinder.h.

    pod 'FBRetainCycleDetector'
  2. Find leaks in custom objects using MLCheck

    master

    To extend leak detection to objects other than UIView or UIViewController, override - (BOOL)willDealloc in your class and use the MLCheck macro to inspect specific properties or objects in the graph.

    - (BOOL)willDealloc {
        if (![super willDealloc]) {
            return NO;
        }
        
        MLCheck(self.viewModel);
        return YES;
    }
  3. Mute assertions for singletons or non-deallocating objects

    master

    If a class is a singleton or is intentionally designed not to be deallocated, prevent MLeaksFinder from reporting it as a leak by overriding the - (BOOL)willDealloc method and returning NO.

    - (BOOL)willDealloc {
        return NO;
    }