Code Monkey home page Code Monkey logo

mleaksfinder's Introduction

中文介绍 | 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;
}

mleaksfinder's People

Contributors

iukey avatar michael2h4ng avatar yangyangyyluck avatar zepo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mleaksfinder's Issues

通过pod管理没生效

通过pod管理代码 pod 'MLeaksFinder', :configurations => ['Debug'],没有生效,load方法都没有执行。如果是把文件夹拖入项目的话就没问题,请问可能是因为什么原因导致的?谢谢!

包含UITableViewCell 的Controller 手势pop

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

使用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
)

I'd suggest add a variable/Macro to switch leaks finder on or off

Hi,

It's a wonderful util to me to find my memory leaks in my APP, it's really useful!

I'd like to suggest add a variable/Macro to switch leaks finder on or off, you know in release package, it's needless to throw a exception to exit the app due to memory leak, but during debug.

Thanks a lot!

roby

请看下这个问题

#ifdef MEMORY_LEAKS_FINDER_RETAIN_CYCLE_ENABLED
#define _INTERNAL_MLF_RC_ENABLED MEMORY_LEAKS_FINDER_RETAIN_CYCLE_ENABLED
#elif COCOAPODS
#define _INTERNAL_MLF_RC_ENABLED COCOAPODS
#endif
一般项目的cocoa pods这个宏一直都是1 那么上线后如果发现循环引用也要弹出alertView了啊

想确认这个是不是误报?

@Zepo 你好,烦请看下
代码比较简单,一个TableviewCell,里边只有一个label,特意在dealloc中加了NSLog输出:
以下是TableviewCell的代码:
qq20160613-0 2x
以下是console的输出,明显看到dealloc有执行NSLog()
qq20160613-1 2x

使用UIImagePickerViewController报内存泄漏

Memory Leak: (
UIImagePickerController,
PLUICameraViewController,
PLImagePickerCameraView
)

Possibly Memory Leak.
In case that PLImagePickerCameraView should not be dealloced, override -willDealloc in PLImagePickerCameraView by returning NO.
View-ViewController stack: (
UIImagePickerController,
PLUICameraViewController,
PLImagePickerCameraView
)

cocoapods环境下的宏定义

在cocoapods环境下想运行非cocooapods的代码,我把NSObject+MemoryLeak.h文件的宏注释掉了,还是不运行,请问判断是否是cocoapods环境的宏是怎么定义的?

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]; }

实际使用过程中controller存在有误报现象

controller中若有网络请求的话,网络请求的block回调中一般都是直接引用self变量的,这样就导致controller除非在网络请求的block落地之前是不会被析构的,如果在这之前页面被pop掉,很容易出现误报

UIWebView相关的leak

项目中存在大量native与UIWebView交互的情况,在vc, webview 都dealloc的情况下还是会中断言,View-ViewController stack: [
TSearchViewController,
UIView,
TWebView,
_UIWebViewScrollView,
UIWebBrowserView
]'

使用过程中遇到这样一个Bug, 望作者解决

在一个ViewController中cellForRow的代理方法里创建一个UISwitch并作为cell的accessoryView,代码如下:
if (indexPath.row == 3) {
UISwitch *s = [[UISwitch alloc] init];
NSUserDefaults *userD = [NSUserDefaults standardUserDefaults];
s.on = [[userD objectForKey:kWiFiKey] boolValue];
[s addTarget:self action:@selector(promptOn:) forControlEvents:UIControlEventValueChanged];
cell.accessoryView = s;
}

当退出当前controller时, 提示内存泄漏,提示如下:
In case that UISwitch should not be dealloced, override -willDealloc in UISwitch by returning NO.
View-ViewController stack: (
LilySettingViewController,
UIView,
UIView,
UITableView,
UITableViewWrapperView,
UITableViewCell,
UISwitch
)

用Instruments工具分析无内存泄漏,并且当前controller的dealloc方法已执行。

release环境打包不需要FBRetainCycleDetector, 区分编译环境

打包release环境的ipa包时, ipa包里含有FBRetainCycleDetector的文件, cocoaPods里这样写的 pod 'MLeaksFinder', :configurations => ['Debug’], 这样打release包时没有MLeaksFinder, 但有FBRetainCycleDetector. MLeaksFinder.podspec里是这样写的, s.dependency 'FBRetainCycleDetector’, 是否要做处理以便区分编译环境?

Memory Leak: UIKeyboardCandidateInlineFloatingView

log as follows:

2016-08-20 15:45:53.723 ERPProject[11890:196011] Memory Leak: (
    MLBReportFormsCommonViewController,
    UIView,
    MLBReportFormsFilteringView,
    UIScrollView,
    UIKeyboardCandidateInlineFloatingView
)
2016-08-20 15:45:53.723 ERPProject[11890:196011] Possibly Memory Leak.
In case that UIKeyboardCandidateInlineFloatingView should not be dealloced, override -willDealloc in UIKeyboardCandidateInlineFloatingView by returning NO.
View-ViewController stack: (
    MLBReportFormsCommonViewController,
    UIView,
    MLBReportFormsFilteringView,
    UIScrollView,
    UIKeyboardCandidateInlineFloatingView
)

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:^{}];
    }

提示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:框架非常赞 : )

按钮leaks问题;gitSpecs问题;

在pushed页面里添加按钮,按钮事件为执行pop。回到上一个页面后,如果没有屏幕interaction则报uibutton被持有,但controller被正确释放。此处应该是苹果的bug,但MLeaksFinder中可能还未添加处理。(SB和代码添加的button都有这个问题。由此推向所有UIControl相关的子类都有该问题,类似UIGesture已验证,但popGesture没问题)
另外,MLeaksFinder目前还未支持gitSpecs的搜索查询,引用pod成问题。

在stroyboard里面使用的问题?

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

还望更新 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

在pushViewController中再present一个UINavigationController, dismiss之后会报内存泄露。

[self.closestViewController.navigationController pushViewController:detailVC animated:YES];

then in detailVC:

SigninViewController *signinVC = [[SigninViewController alloc] init];
signinVC.delegate = self;
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:signinVC];
[self presentViewController:nav animated:YES completion:nil];

If I call dismiss in signInVC:

[self dismissViewControllerAnimated:YES completion:nil];

modal viewcontroller closed and will report memory leak:

2017-04-30 10 44 35

一个crash问题

Zepo@66b071f

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.