LeakCanary清理HPROF文件

时间:2018-01-25 04:07:38

标签: android memory-leaks leakcanary hprof

我有一个集成LeakCanary以检测内存泄漏的项目。我知道它使用HAHA将内存转储到hprof文件以检测泄漏。

但每次我从Android Studio运行应用程序时,它都会触发转储过程并创建一个大约hprof MB大小的新60-70文件。

enter image description here

当它导致我的设备充满内存。当我尝试删除泄漏应用程序中的泄漏日志时,一些关闭的hprof文件未被清除(文件名中有_pending),如下图所示。我必须手动删除它。

enter image description here

我是LeakCanary的新手,请帮助我如何降低转储过程的频率,以及如何自动清除所有hprof文件。

2 个答案:

答案 0 :(得分:0)

我实现了 leakcanary版本1.5.4 android studio 3.5.1

依赖性是

debugImplementation 'com.squareup.leakcanary:leakcanary-android:1.5.4'
releaseImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.4'

在模拟器中,在复制内存泄漏后, hprof文件路径可能是:

 /data/user/10/<app_package_name>/files/leakcanary/<filename>.hprof

答案 1 :(得分:0)

尝试升级到LeakCanary的最新版本:https://square.github.io/leakcanary/getting_started/

它应该在清理hprof文件方面做得更好。如果没有,请在项目上提交错误

要立即删除所有现有的hprof文件,可以使用“ adb shell”并使用“ rm”将其全部删除。