Skip to content

MLeaksFinder有时候会误报? #80

Closed
@willylee007

Description

@willylee007

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

Activity

Zepo

Zepo commented on Nov 14, 2017

@Zepo
Collaborator

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

willylee007

willylee007 commented on Nov 14, 2017

@willylee007
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

willylee007 commented on Nov 14, 2017

@willylee007
Author

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

DreamBuddy

DreamBuddy commented on Nov 17, 2017

@DreamBuddy

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

willylee007

willylee007 commented on Nov 20, 2017

@willylee007
Author

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

Zepo

Zepo commented on Nov 20, 2017

@Zepo
Collaborator

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

DreamBuddy

DreamBuddy commented on Nov 20, 2017

@DreamBuddy

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

DreamBuddy

DreamBuddy commented on Nov 20, 2017

@DreamBuddy

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

DreamBuddy

DreamBuddy commented on Nov 20, 2017

@DreamBuddy

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

ghost

ghost commented on Nov 27, 2017

@ghost

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

Jinzhengxuan

Jinzhengxuan commented on Dec 5, 2017

@Jinzhengxuan

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

Jinzhengxuan

Jinzhengxuan commented on Dec 5, 2017

@Jinzhengxuan

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

Zepo

Zepo commented on Dec 7, 2017

@Zepo
Collaborator

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

liubin1777

liubin1777 commented on Dec 8, 2017

@liubin1777

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

lingfengmarskey

lingfengmarskey commented on Dec 8, 2017

@lingfengmarskey

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

10 remaining items

ChavezChen

ChavezChen commented on Jan 16, 2018

@ChavezChen

我这里也出现了报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

ChavezChen commented on Jan 18, 2018

@ChavezChen

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

willylee007

willylee007 commented on Jan 18, 2018

@willylee007
Author

楼上正解. close.

binzi56

binzi56 commented on Mar 14, 2019

@binzi56

正解

AgoniNemo

AgoniNemo commented on Nov 1, 2019

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

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

cddjr

cddjr commented on Nov 1, 2019

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

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

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

KennyHito

KennyHito commented on Mar 3, 2022

@KennyHito

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

AllenChen1988

AllenChen1988 commented on Jul 21, 2022

@AllenChen1988

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

神了

NighWish

NighWish commented on Feb 23, 2023

@NighWish

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

NighWish

NighWish commented on Feb 23, 2023

@NighWish

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

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

Tiaotiaotiao

Tiaotiaotiao commented on Dec 21, 2023

@Tiaotiaotiao

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

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

是的 坑爹啊 😭

wxm5558

wxm5558 commented on Dec 9, 2024

@wxm5558

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

TangChunhui commented on Feb 20, 2025

@TangChunhui

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @liubin1777@cddjr@wxm5558@DreamBuddy@seuzxh

        Issue actions

          MLeaksFinder有时候会误报? · Issue #80 · Tencent/MLeaksFinder