Tencent / MLeaksFinder

Find memory leaks in your iOS app at develop time.
Other
5.42k stars 934 forks source link

提示UIAlertController有leak #12

Open xilin opened 8 years ago

xilin commented 8 years ago

这个我们自己无法控制吧? 检测的原理是啥呢?

Zepo commented 8 years ago

我这边好像不会报 UIAlertController。。 检测的原理可以参考这篇文章:http://wereadteam.github.io/2016/02/22/MLeaksFinder/

Zepo commented 8 years ago

试了一下,无论用 UIAlertController 还是 UIAlertView 都无法重现,能贴一下代码吗?

KittenYang commented 8 years ago

@Zepo 我也遇到了。我用的是 UIActivityViewController ,可以保证的是代码里没有用到一处 UIAlertController ,可在 UIActivityViewController dismiss 完了之后依然提示 UIAlertController 泄露。原因是 UIActivityViewController 中有一个私有变量 UIAlertController ,但归根结底还是 MLeaksFinder 对 UIAlertController 的泄露误判。

Zepo commented 8 years ago

这是模拟器的 bug。

当使用Mac电脑键盘的“return”键把 UIAlertController dismiss 掉时,UIAlertController 不会被释放,确实是泄漏了; 当使用 UIAlertController 上的 UIAlertAction 按钮,或者使用模拟器的软键盘的“return”键时,UIAlertController 能正常释放。

这个是模拟器的内存泄漏,MLeaksFinder 无法做判断。

Tonyhe666 commented 8 years ago

我在iOS9.0真机上调试,也会提示这个Possibly Memory Leak. In case that UIAlertController should not be dealloced, override -willDealloc in UIAlertController by returning NO. View-ViewController stack: ( UIAlertController )

Tonyhe666 commented 8 years ago

我知道原因了,是我自己的问题。我在使用的时候:action闭包里面调用了alertVC.dismissViewControllerAnimated(true, completion: nil) 导致alertVC泄漏了。工具很好用,解决了好几个泄漏。谢谢!

Andy1984 commented 8 years ago

一般的AlertView确实有报内存泄露, 还有UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:@[self.url] applicationActivities:@[]]; [self presentViewController:activityViewController animated:YES completion:nil]; 也会报泄露

ETListener commented 8 years ago

使用的过程中也出现了这个问题。我们工程使用了 BlocksKit ,会是 BlocksKit 和MLeaksFinder一起使用出现的问题么。

Zepo commented 8 years ago

能否做个 demo project,不然无法定位问题

ETListener commented 8 years ago

我尝试写了个demo,已经证明和BlocksKit无关,应该还是我们工程的问题。 原工程的问题目前还有没找到,报错信息如下: Retain Cycle: ( "-> __associated_object -> UIAlertController ", "-> _cancelAction -> UIAlertAction " ) 目前的处理方式是把UIAlertController的willDealloc方法覆写并return NO了。 这个工具还是很好用的,谢谢。

Zepo commented 8 years ago

这个就是 objc_setAssociatedObject 导致的了

vaintwyt commented 7 years ago

UIAlertController如果是当前界面的一个属性或者成员变量,确实会误报。

因为dismissViewController后,这个变量还没有释放。

在NSObject+MemoryLeak的classNamesInWhiteList中增加UIAlertController到白名单就行了,不需要重写willDealloc方法

abellee commented 7 years ago

如果UIAlertController里有个textField 退出也是报leak了

TheBloodElf commented 7 years ago

UIAlertController里有个textField情况,我是如下情况有报leak:在确认按钮中通过uIAlert.textFields访问了textField;解决方法是:用外面一个局部变量指向UIAlertController中的textField,确认按钮中使用此变量

MrCaiWH commented 6 years ago

同样碰到了这个问题,单独写了个demo没有复现,但是在项目中必现,报这个错:In case that UIAlertController should not be dealloced, override -willDealloc in UIAlertController by returning NO。

我写了个子类KLUIAlertController集成自UIAlertController,当alert消息时,该类的dealloc方法也会走,好像除了误报,已经没法解释了。日志信息写 Possibly Memory Leak,也就是说作者也不确定是真的内存泄漏??@Zepo

这是日志信息:

2017-11-17 17:50:39.474139+0800 iKaoYan[8576:1907849] Memory Leak: ( KLUIAlertController ) 2017-11-17 17:50:39.474708+0800 iKaoYan[8576:1907849] Possibly Memory Leak. In case that KLUIAlertController should not be dealloced, override -willDealloc in KLUIAlertController by returning NO. View-ViewController stack: ( KLUIAlertController ) <KLUIAlertController.m : 24> -[KLUIAlertController dealloc] 2017-11-17 17:50:39.475222+0800 iKaoYan[8576:1907849] KLUIAlertController-释放了

2017-11-17 17:50:40.046771+0800 iKaoYan[8576:1907849] Object Deallocated: ( KLUIAlertController )

hiseason commented 6 years ago

我也遇到了这个问题, 声明全局变量, 修改 dismiss 时的 alertVc为 weakSelf.alertController @property (strong, nonatomic) XSAlertController *alertController;
[weakSelf.alertController dismissViewControllerAnimated:YES completion:nil]; 之前是 [alertVc dismissViewControllerAnimated:YES completion:nil]; 但是不知道为什么这样改就好了, 直接用 alertVc 会造成 vc 对 alertVc强引用,但是出了作用域后 alertVc 不就应该被销毁了吗? 希望大神指点一下 @Tonyhe666

Tonyhe666 commented 6 years ago

出了作用域不一定被销毁,可能闭包循环引用形成环了。alertVc->block->alertVc