Blankj / AndroidUtilCode

:fire: Android developers should collect the following utils(updating).
https://blankj.com/2016/07/31/android-utils-code/
Apache License 2.0
33.24k stars 10.67k forks source link

ToastUtils会有内存泄漏 #720

Closed wimwu closed 5 years ago

wimwu commented 5 years ago

Describe the bug

A clear and concise description of what the bug is.

The code of bug

看了@254的issues,问题应该还在,没有使用自定义布局,就简单的ToastUtils.showShort(int stringRes)调用,使用了 leaks检测工具,很容易出现

Please delete the current line and the followings.

Thank you for supporting AndroidUtilCode.

Blankj commented 5 years ago

我这边没有检测到哦

Blankj commented 5 years ago

demo 也有 leaks,会出现吗

wimwu commented 5 years ago

看了下源码中toast的创建 ToastUtils.sToast = ToastUtils.ToastFactory.makeToast(Utils.getTopActivityOrApp(), text, duration); sToast是静态变量,toast的上下文是顶部的activity,导致关闭时被持有不能释放

lvyandev commented 5 years ago

同样发现泄露

lvyandev commented 5 years ago

1.22.1修复了吗

Blankj commented 5 years ago

下个版本吧,sToast 只是暂时泄漏了,之后会回收的应该是。

MrWude commented 5 years ago

1.22.1还存在问题

iToast = ToastFactory.makeToast(Utils.getTopActivityOrApp(), text, duration);

应该不是短暂的泄漏

Blankj commented 5 years ago

我也不知道啥时候居然把

iToast = ToastFactory.makeToast(Utils.getApp(), text, duration);

改成了

iToast = ToastFactory.makeToast(Utils.getTopActivityOrApp(), text, duration);

新版 1.22.2 内存泄漏我已经修复啦,不论是否有通知权限都不会泄漏了。

SummerMineJack commented 5 years ago

1.24.3 还是存在内存泄漏