Skip to content

MLeaksFinder有时候会误报? #80

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
willylee007 opened this issue Nov 14, 2017 · 38 comments
Closed

MLeaksFinder有时候会误报? #80

willylee007 opened this issue Nov 14, 2017 · 38 comments

Comments

@willylee007
Copy link

您好, 首先感谢分享这么棒的工具.
测试当中, 打断点到控制器的dealloc, 发现可以正常走到dealloc, 但MLeaksFinder会报Memory Leak. 请问这是误报还是会受什么因素影响

@Zepo
Copy link
Collaborator

Zepo commented Nov 14, 2017

请贴一下详细信息,弹窗的截图等

@willylee007
Copy link
Author

输出下面的信息:
2017-11-14 11:58:37.373501+0800 lin-sdk-demo[3933:3009455] Memory Leak: (
LoginController,
UIView,
UITextField
)
2017-11-14 11:58:37.374111+0800 lin-sdk-demo[3933:3009455] Possibly Memory Leak.
In case that UITextField should not be dealloced, override -willDealloc in UITextField by returning NO.
View-ViewController stack: (
LoginController,
UIView,
UITextField
)
2017-11-14 11:58:37.416103+0800 lin-sdk-demo[3933:3009455] Memory Leak: (
LoginController,
UIView,
UITextField
)
2017-11-14 11:58:37.416508+0800 lin-sdk-demo[3933:3009455] Possibly Memory Leak.
In case that UITextField should not be dealloced, override -willDealloc in UITextField by returning NO.
View-ViewController stack: (
LoginController,
UIView,
UITextField
)

@willylee007
Copy link
Author

简单说明一下, 这是个简单的登录页面, 有几个简单的textfield, 有个登录按钮, 点击会进行登录请求, 然后loading有个SVProgresshud, 点击空白去掉hud(touchesBegan方法里实现的), 整个页面大概这些逻辑.

@DreamBuddy
Copy link

@willylee007 @Zepo 我也是在iOS11下 UITextField报没释放~

@willylee007
Copy link
Author

@DreamBuddy +1 .页面是销毁的, 估计11下需要对UITextField作额外处理 @Zepo

@Zepo
Copy link
Collaborator

Zepo commented Nov 20, 2017

试了没能重现,能否提供 demo?

@DreamBuddy
Copy link

@Zepo Demo确实没复现,猜测是某些框架引起的,我正在实验

@DreamBuddy
Copy link

测试了一个晚上,很是奇怪 secureTextEntry 为 YES的时候就会内存泄漏,但是demo中即使设置为YES 也不会。。

@DreamBuddy
Copy link

@willylee007 你试试。。看看secureTextEntry这个参数有没有关系

@ghost
Copy link

ghost commented Nov 27, 2017

我也有这个问题,,不清楚怎么解决,,求教

@Jinzhengxuan
Copy link

2017-12-05 21:38:35.766938+0800 MiaoMoreNew[3907:417197] Memory Leak: (
UGUnbindMobileViewController,
UIView,
MMTextField
)

@Jinzhengxuan
Copy link

发现误报,ViewController已经释放了,但是会报MMTextField的内存溢出

@Zepo
Copy link
Collaborator

Zepo commented Dec 7, 2017

@Jinzhengxuan 你这个报的是 MMTextField 没释放

@liubin1777
Copy link

在iOS11下UITextField好像不会调用Dealloc被释放,是不是iOS11的一个Bug

@lingfengmarskey
Copy link

lingfengmarskey commented Dec 8, 2017

可以重现的bug xcode9.2 ios11.2demo @Zepo

@willylee007
Copy link
Author

上面这个dmeo可以测出泄漏. 虚拟机上没有测出. 难道是真机系统的一个bug?

@lingfengmarskey
Copy link

@willylee007 11.2 模拟器上也可以重现

@willylee007
Copy link
Author

我这个虚拟机11.1的系统. 真机11.2的系统.

@seuzxh
Copy link

seuzxh commented Dec 11, 2017

我也发现这个问题了。。。
我用 真机11.2 模拟器11.2 都会报 UITextField 未释放
我是继承了 UITextField 派生了自己的 业务textfield 来试用的

@Darren-chenchen
Copy link

我也有这个问题,我自己的手机iphone6 11.1,没有报UITextField未释放,但是我同事的手机iphone8p,11.2,会一直报UITextField 未释放
View-ViewController stack: (
"CloudscmSwift.ProductDetailVC",
UIView,
"CloudscmSwift.ChoosePropertitesView",
UIView,
"CloudscmSwift.AmountControl",
UITextField
)
不知道什么问题呀??

@cddjr
Copy link

cddjr commented Dec 17, 2017

昨天升级11.2.1后 就开始报UITextField泄漏了, 升级前是11.1系统,没有这个问题。

@YearRen
Copy link

YearRen commented Dec 18, 2017

uitextfiled 确实会误报,看了一篇简书,不知道有没有用http://www.jianshu.com/p/fc90383df61f

@Beyond-Chao
Copy link

误报:

Retain Cycle: (
"-> _provider -> UITextField ",
"-> _textContentView -> _UITextFieldContentView "
)

@mayan29
Copy link

mayan29 commented Jan 4, 2018

直接在 ViewController 中添加 UITextField,ViewController 释放了,也会误报 UITextField 没有释放,真机和模拟器都是 iOS 11.2

目前可以添加下列类别来暂时屏蔽掉误报问题(不用设置头文件,直接在项目中创建即可):

#import <UIKit/UIKit.h>

@interface UITextField (MemoryLeak)

@end
#import "UITextField+MemoryLeak.h"
#import "NSObject+MemoryLeak.h"

@implementation UITextField (MemoryLeak)

- (BOOL)willDealloc {
    
    return NO;
}

@end

很喜欢这个检测工具,望能修复

@TuyaRonbin
Copy link

2018-01-05 20:19:08.907351+0800 TuyaSmartPublic[15439:7965494] Memory Leak: (
"TYFeitAddGroupsViewController",
"UIView",
"UITextField",
)

@ChavezChen
Copy link

ChavezChen commented Jan 16, 2018

我这里也出现了报UITextField内存泄露的问题,楼上有同学提供了一种解决11.2误报的思路非常的好,但是其实框架的提供者有为我们提供了一个更好的解决方法:就是白名单,我们可以把UITextField加入到白名单内就好了,提供我的修改建议,在框架的NSObject+MemoryLeak.m 这个文件下 ,第114行的函数就是返回白名单数组,在这个方法里面添加2行代码,判断一下当前版本是否是11以上,然后将UITextField加入白名单即可,这样不必添加分类,iOS11以下也能监测UITextField的内存泄漏问题

+ (NSMutableSet *)classNamesWhitelist {
    static NSMutableSet *whitelist = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        whitelist = [NSMutableSet setWithObjects:
                     @"UIFieldEditor", // UIAlertControllerTextField
                     @"UINavigationBar",
                     @"_UIAlertControllerActionView",
                     @"_UIVisualEffectBackdropView",
                     nil];
        
        // System's bug since iOS 10 and not fixed yet up to this ci.
        NSString *systemVersion = [UIDevice currentDevice].systemVersion;
        if ([systemVersion compare:@"10.0" options:NSNumericSearch] != NSOrderedAscending) {
            [whitelist addObject:@"UISwitch"];
        }
       // 将UITextField加入白名单
        if ([systemVersion compare:@"11.0" options:NSNumericSearch] != NSOrderedAscending) {
            [whitelist addObject:@"UITextField"];
        }
    });
    return whitelist;
}

@ChavezChen
Copy link

https://forums.developer.apple.com/thread/94323 UITextField在11.2会报内存泄露,实锤是苹果系统的bug,楼主的框架非常准确,它就是内存泄露了~👍👍👍

@willylee007
Copy link
Author

楼上正解. close.

@binzi56
Copy link

binzi56 commented Mar 14, 2019

正解

@AgoniNemo
Copy link

UITextField *textField = [[UITextField alloc]init];
[self.view addSubview:textField];
[textField becomeFirstResponder];

以上代码会内存泄漏在iOS 12+

@cddjr
Copy link

cddjr commented Nov 1, 2019

UITextField *textField = [[UITextField alloc]init];
[self.view addSubview:textField];
[textField becomeFirstResponder];

以上代码会内存泄漏在iOS 12+

ios自身的问题,参考上面的代码屏蔽

@KennyHito
Copy link

将textfield 的autocorrectionType属性设置为NO,亲测有效!

@AllenChen1988
Copy link

将textfield 的autocorrectionType属性设置为NO,亲测有效!

神了

@NighWish
Copy link

iOS15上 autocorrectionType = NO也无效,只有一进来不调用becomeFirstResponder

@NighWish
Copy link

iOS15上 autocorrectionType = NO也无效,只有一进来不调用becomeFirstResponder

keyboardType = .emailAddress会释放,keyboardType = .numberPad不会释放

@Tiaotiaotiao
Copy link

iOS15上 autocorrectionType = NO也无效,只有一进来不调用becomeFirstResponder

keyboardType = .emailAddress会释放,keyboardType = .numberPad不会释放

是的 坑爹啊 😭

@wxm5558
Copy link

wxm5558 commented Dec 9, 2024

when i set keboardType = .emailAddress or .numbersAndPunctuation, .namePhonePad
it will call deinit normally, otherwise it dose not call deinit any more.

I am running into this issue too, can anyone solve this problem?
does it has private API could work?

@TangChunhui
Copy link

when i set keboardType = .emailAddress or .numbersAndPunctuation, .namePhonePad it will call deinit normally, otherwise it dose not call deinit any more.

I am running into this issue too, can anyone solve this problem? does it has private API could work?

怎么解决这个问题的啊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests