Find memory leaks in your iOS app at develop time.

Overview

中文介绍 | FAQ中文

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.

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.

WARNING: FBRetainCycleDetector is removed from the podspec due to Facebook's BSD-plus-Patents license. If you want to use FBRetainCycleDetector to find retain cycle, add pod 'FBRetainCycleDetector' to your project's Podfile and turn the macro MEMORY_LEAKS_FINDER_RETAIN_CYCLE_ENABLED on in MLeaksFinder.h.

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.

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.

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 {
    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.

- (BOOL)willDealloc {
    if (![super willDealloc]) {
        return NO;
    }
    
    MLCheck(self.viewModel);
    return YES;
}
Comments
  • 提示UITableViewCellContentView未释放(代码创建的tableview)

    提示UITableViewCellContentView未释放(代码创建的tableview)

    我也遇到了,用的系统样式自带的cell,在返回cell的方法如下:

    • (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellId forIndexPath:indexPath]; VankeShopModel *shop = self.results[indexPath.row]; cell.textLabel.text = [NSString stringWithFormat:@"%@【%@】", shop.name, shop.code]; return cell; }

    MLeakFinder提示: Possibly Memory Leak. In case that UITableViewCellContentView should not be dealloced, override -willDealloc in UITableViewCellContentView by returning NO. View-ViewController stack: ( ChooseShopViewController, UIView, UITableView, UITableViewWrapperView, UITableViewCell, UITableViewCellContentView )

    实在找不到哪里有内存泄露,希望对你完善框架有帮助。 PS:框架非常赞 : )

    opened by jzhang0480 10
  • 包含UITableViewCell 的Controller 手势pop

    包含UITableViewCell 的Controller 手势pop

    Retain Cycle: ( "-> mockParent -> CartTableViewCell ", "-> __associated_object -> __NSDictionaryM ", "-> _AXTableViewCellInternal " ) 出现 这个 这个貌似是系统UIKit下边的一个类。。大神 我这是怎么了 求指教

    opened by DreamBuddy 5
  • 使用Xib 添加的UITableview 检查未释放

    使用Xib 添加的UITableview 检查未释放

    添加断点,看到已经执行了MainViewController的dealloc方法。 但是提示UITableview没有被释放,这个UITableview是通过Xib添加的。

    In case that UITableView should not be dealloced, override -willDealloc in UITableView by returning NO. View-ViewController stack: ( MainViewController, UIView, UIView, UITableView )

    opened by yinanwang1 5
  • 在stroyboard里面使用的问题?

    在stroyboard里面使用的问题?

    在实际项目中,用了MLeaksFinder,但在SB中发现了一个问题。例如:在页面A跳转到页面B。页面B中有一个按钮,点击按钮是返回到页面A,如果直接手势返回,不会有什么问题。如果是点击页面B中的按钮返回,就会断言说按钮没有释放掉。不知道什么问题,求解答,写了个demo: https://github.com/vjieshao/MLeaksFinderTest 谢谢!

    opened by vjieshao 4
  • Compile error in Xcode 12.5 .

    Compile error in Xcode 12.5 .

    报错信息:

    引入的库 FBRetainCycleDetector 报错: Pods/FBRetainCycleDetector/FBRetainCycleDetector/Layout/Classes/FBClassStrongLayout.mm:202:21: error: cannot initialize a parameter of type 'id _Nonnull' with an rvalue of type 'Class'

    版本信息:

    1.0.0

    报错源码上下文:

    NSArray<id<FBObjectReference>> *FBGetObjectStrongReferences(id obj,
                                                                NSMutableDictionary<Class, NSArray<id<FBObjectReference>> *> *layoutCache) {
      NSMutableArray<id<FBObjectReference>> *array = [NSMutableArray new];
    
      __unsafe_unretained Class previousClass = nil;
      __unsafe_unretained Class currentClass = object_getClass(obj);
    
      while (previousClass != currentClass) {
        NSArray<id<FBObjectReference>> *ivars;
        
        if (layoutCache && currentClass) {
          ivars = layoutCache[currentClass];
        }
        
        if (!ivars) {
          ivars = FBGetStrongReferencesForClass(currentClass);
          if (layoutCache && currentClass) {
            layoutCache[currentClass] = ivars; // 此处报错
          }
        }
        [array addObjectsFromArray:ivars];
    
        previousClass = currentClass;
        currentClass = class_getSuperclass(currentClass);
      }
    
      return [array copy];
    }
    
    opened by sapphirezzz 3
  • 还望更新 Pod 到0.2

    还望更新 Pod 到0.2

    现在 pod 上的版本是0.1的.

    使用01的版本的时候,发现了个 bug. 在 vc释放的时候,去调用 self.view 导致调用 [UIViewController loadViewIfRequired]

    即为由 frame5->frame4->frame3的过程.

    _cmd="doFetchDataWithParms:requestComplete:", parms=3 key/value pairs, complete=0x000000012e2e2230) + 96 at MeCollectController.m:21, queue = 'com.apple.main-thread', stop reason = breakpoint 4.1
      * frame #0: 0x00000001001785dc`-[MeCollectController doFetchDataWithParms:requestComplete:](self=0x000000012e6928b0, _cmd="doFetchDataWithParms:requestComplete:", parms=3 key/value pairs, complete=0x000000012e2e2230) + 96 at MeCollectController.m:21
        frame #1: 0x0000000100178a5c`-[MeCollectController fetchData](self=0x000000012e6928b0, _cmd="fetchData") + 252 at MeCollectController.m:45
        frame #2: 0x0000000100178570`-[MeCollectController viewDidLoad](self=0x000000012e6928b0, _cmd="viewDidLoad") + 256 at MeCollectController.m:17
        frame #3: 0x000000018680cc40 UIKit`-[UIViewController loadViewIfRequired] + 996
        frame #4: 0x000000018680c844 UIKit`-[UIViewController view] + 28
        frame #5: 0x00000001014653b0 MLeaksFinder`-[UIViewController(self=0x000000012e6928b0, _cmd="willDealloc") willDealloc] + 892 at UIViewController+MemoryLeak.m:75
        frame #6: 0x0000000101465244 MLeaksFinder`-[UIViewController(self=0x000000012e690ae0, _cmd="willDealloc") willDealloc] + 528 at UIViewController+MemoryLeak.m:65
        frame #7: 0x0000000101464de4 MLeaksFinder`-[UIViewController(self=0x000000012e690ae0, _cmd="viewDidDisappear:", animated=YES) swizzled_viewDidDisappear:] + 156 at UIViewController+MemoryLeak.m:32
        frame #8: 0x0000000192e2d394 UIKit`-[UIViewControllerAccessibility viewDidDisappear:] + 52
        frame #9: 0x00000001002d6ad0`-[UIViewController(self=0x000000012e690ae0, _cmd=<unavailable>, animated=<unavailable>) btg_swizzleViewDidDisappear:] + 28 at UIViewController+BTGMethodSwizzler.m:69
        frame #10: 0x0000000186825314 UIKit`-[UIViewController _setViewAppearState:isAnimating:] + 532
        frame #11: 0x000000018689d0cc UIKit`-[UIViewController __viewDidDisappear:] + 144
    

    查看源码后发现使用 pod 上的 v0.1版本的缘故:

    https://git.io/vK1M1

    还请更新 pod 到0.2版本

    3Q

    opened by urmyfaith 3
  • 同样遇到在执行了dealloc 方法,还是会报内存泄漏

    同样遇到在执行了dealloc 方法,还是会报内存泄漏

    2017-09-26 18:24:10.158648+0800 BMOnlineManagement[14988:6444866] 控制器[BMSettingViewController]销毁了
    2017-09-26 18:24:11.788183+0800 BMOnlineManagement[14988:6444866] Memory Leak: (
    	BMSettingViewController,
    	UIView
    )
    2017-09-26 18:24:11.788586+0800 BMOnlineManagement[14988:6444866] Possibly Memory Leak.
    In case that UIView should not be dealloced, override -willDealloc in UIView by returning NO.
    View-ViewController stack: (
        BMSettingViewController,
        UIView
    )
    
    
    opened by fenglh 2
  • 一个crash问题

    一个crash问题

    https://github.com/Zepo/MLeaksFinder/commit/66b071fafab2bbf0f21bc88f434197fc84c6a56d

    您好,不知道在哪里请教问题比较合适。所以还借此请教下,这个commit的修改里,为什么采用对象比较就会crash。而采用对象的地址比较就没问题呢?

    opened by SatanWoo 2
  • Why ViewController presentation always leak?

    Why ViewController presentation always leak?

    ViewController A present ViewController B and B implementation this method, B's root view always leak - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { [self cancelAction:nil]; [self dismissViewControllerAnimated:animated completion:nil]; }

    opened by weiminghuaa 2
  •  UIImagePickerController with MLeaksFinder,crash no reasonable. i need help~~

    UIImagePickerController with MLeaksFinder,crash no reasonable. i need help~~

    pragma mark -

    pragma mark -UIImagePickerController

    • (void)jumpToCameraOrPhotoLibraryWithType:(UIImagePickerControllerSourceType)type{ UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init]; imagePickerController.delegate = self; imagePickerController.allowsEditing = YES; imagePickerController.sourceType = type; [self presentViewController:imagePickerController animated:YES completion:^{}]; }

    // callback

    • (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage]; self.imagUAvrtar.image = image; self.img2upload= image; [picker dismissViewControllerAnimated:YES completion:^{}]; }
    • (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{ [self dismissViewControllerAnimated:YES completion:^{}]; }
    opened by mjiulee 2
  • willDealloc中延迟执行的GCD中对weak Self为什么要使用strongSelf?

    willDealloc中延迟执行的GCD中对weak Self为什么要使用strongSelf?

    1. __strong id strongSelf = weakSelf;的意义是什么?
    2. __strong id strongSelf = weakSelf;和__strong typeof(weakSelf) self = weakSelf;还不太一样,后者在GCD之后对weakSelf解除强引用,前者在GCD之前就不对weakSelf进行强引用了。
    opened by yangguanghei 0
  • Fail to find retain cycle

    Fail to find retain cycle

    Whenever an alert comes up showing a memory leak in a view or viewController. post clicking on retain cycle button, it always shows the error of failing to find retain cycle.

    opened by arinjay 1
Owner
Tencent
Tencent
In-app memory usage monitoring for iOS

What's Stats Stats displays load statuses such as the memory usage, the CPU load, and the number of subviews in-app, and in realtime. How to use Just

Shuichi Tsutsumi 170 Sep 18, 2022
Find common xib and storyboard-related problems without running your app or writing unit tests.

IBAnalyzer Find common xib and storyboard-related problems without running your app or writing unit tests. Usage Pass a path to your project to ibanal

Arek Holko 955 Oct 15, 2022
iOS tool that helps with profiling iOS Memory usage.

FBMemoryProfiler An iOS library providing developer tools for browsing objects in memory over time, using FBAllocationTracker and FBRetainCycleDetecto

Facebook Archive 3.4k Dec 7, 2022
Exclude files from Time Machine backups

tmexclude A small macOS command-line tool to flag a file/folder to be excluded from Time Machine backups by setting the com.apple.metadata:com_apple_b

Jacob Greenfield 1 Jan 17, 2022
decoupling between modules in your iOS Project. iOS模块化过程中模块间解耦方案

DecouplingKit 中文readme Podfile platform :ios, '7.0' pod 'DecouplingKit', '~> 0.0.2' DecouplingKit, decoupling between modules in your iOS Project. D

coderyi 139 Aug 23, 2022
An Xcode formatter plug-in to format your swift code.

Swimat Swimat is an Xcode plug-in to format your Swift code. Preview Installation There are three way to install. Install via homebrew-cask # Homebrew

Jintin 1.6k Jan 7, 2023
Asserts on roids, test all your assumptions with ease.

KZAsserts - Asserts on roids, test all your assumptions with ease. There are many ways in which we can improve quality of our code-base, Assertions ar

Krzysztof Zabłocki 101 Jul 1, 2022
An xcconfig (Xcode configuration) file for easily turning on a boatload of warnings in your project or its targets.

Warnings This is an xcconfig file to make it easy for you to turn on a large suite of useful warnings in your Xcode project. These warnings catch bugs

Peter Hosey 438 Nov 8, 2022
Skredvarsel app - an iOS, iPadOS, and macOS application that provides daily avalanche warnings from the Norwegian Avalanche Warning Service API

Skredvarsel (Avalanche warning) app is an iOS, iPadOS, and macOS application that provides daily avalanche warnings from the Norwegian Avalanche Warning Service API

Jonas Follesø 8 Dec 15, 2022
Simple iOS app blackbox assessment tool. Powered by frida.re and vuejs.

Discontinued Project This project has been discontinued. Please use the new Grapefruit #74 frida@14 compatibility issues frida@14 introduces lots of b

Chaitin Tech 1.6k Dec 16, 2022
Manipulates the undocumented interchange format for the Apple Notes app.

NotesArchive A Swift package for reading and writing an undocumented interchange format for the Apple Notes app in macOS 12 Monterey1. Enabling the De

Zachary Waldowski 7 Jul 5, 2022
iOS project bootstrap aimed at high quality coding.

iOS Project bootstrap How do you setup your iOS projects? Since we are approaching 2015 I’m working on refreshing my project bootstrap. I’ve decided t

Krzysztof Zabłocki 2k Dec 23, 2022
iOS library to help detecting retain cycles in runtime.

FBRetainCycleDetector An iOS library that finds retain cycles using runtime analysis. About Retain cycles are one of the most common ways of creating

Facebook 4.1k Dec 26, 2022
Awesome bug reporting for iOS apps

Buglife is an awesome bug reporting SDK & web platform for iOS apps. Here's how it works: User takes a screenshot, or stops screen recording User anno

Buglife 498 Dec 17, 2022
Makes it easier to support older versions of iOS by fixing things and adding missing methods

PSTModernizer PSTModernizer carefully applies patches to UIKit and related Apple frameworks to fix known radars with the least impact. The current set

PSPDFKit Labs 217 Aug 9, 2022
Flexible bug report framework for iOS

Clue is a simple smart-bug report framework for iOS, which allows your users to record full bug/crash report and send it to you as a single .clue file

Ahmed Sulaiman 279 Nov 3, 2022
The project used in the iOS Architect Crash Course lectures

iOS Architect Crash Course • August 2nd-8th • EssentialDeveloper.com https://www.essentialdeveloper.com/ios-architect-crash-course/aug-2021-a5220 It's

Aleksei Korolev 1 Jul 20, 2022
A library that enables dynamically rebinding symbols in Mach-O binaries running on iOS.

fishhook fishhook is a very simple library that enables dynamically rebinding symbols in Mach-O binaries running on iOS in the simulator and on device

Meta 4.9k Jan 8, 2023
Find memory issues & leaks in your iOS app without instruments

HeapInspector Find memory issues & leaks in your iOS app HeapInspector is a debug tool that monitors the memory heap with backtrace recording in your

Christian Menschel 1.8k Nov 24, 2022
👷‍♀️ Closure-based delegation without memory leaks

Delegated 2.0 Delegated is a super small package that helps you avoid retain cycles when using closure-based delegation. New Medium post here. Origina

Oleg Dreyman 703 Oct 8, 2022