当我 运行 在分析模式下我的应用程序停止响应

My app stops responding when I run it on the Profiling mode

我的 Android 应用程序的长时间 运行 会话中出现一些内存不足错误。为了找到原因,我尝试使用 Android Studio Profiler,但它停止工作并在使用后 10 秒内冻结应用程序。

这里有 Android Studio 屏幕的屏幕截图。它在第一秒内记录活动,然后冻结应用程序并停止记录任何内容 -> https://ibb.co/QXLhqnz

我的 logcat 阅读的最后几行(最后几行随着时间的推移不断重复,我更改了包名)

2019-04-09 08:42:41.151 19728-20399/br.com.xxxxx V/StudioProfiler: Live memory tracking enabled.
2019-04-09 08:42:41.151 19728-20399/br.com.xxxxx V/StudioProfiler: JNIEnv not attached
2019-04-09 08:42:41.483 19728-20399/br.com.xxxxx V/StudioProfiler: Loaded classes: 8894
2019-04-09 08:42:51.688 19728-20399/br.com.xxxxx E/zygote: E[0]:Timed out waiting for threads to suspend(br.com.xxxxx), waited for 10.000s
2019-04-09 08:43:01.689 19728-20399/br.com.xxxxx E/zygote: E[0]:Timed out waiting for threads to suspend(br.com.xxxxx), waited for 20.000s
2019-04-09 08:43:11.689 19728-20399/br.com.xxxxx E/zygote: E[0]:Timed out waiting for threads to suspend(br.com.xxxxx), waited for 30.000s

提前感谢任何帮助。

Android Studio Profiler 可能不是完成该任务的合适工具。首先用 LeakCanary 识别可能的内存泄漏并修复它们, 那么您应该能够使用探查器,而无需 stalled/killed 个线程。没有提供最少的代码,这可能是最好的答案。

这种行为的原因可能是,ART 会终止停滞的线程,而 Profiler 会一直等待它们响应,这显然永远不会发生,因为它们已不存在。

错误信息来自ART,请看thread_list.cc。在 Dalvik VM 上,它可能表现不同(很可能由于 OOM 而强制关闭,或者它可能使 VM 崩溃)。这可能值得一试。在分析时介入它也可能是一种选择,但它远不如 LeakCanaray 方便。


更新:Android Studio 3.6.2 发行说明状态:

Improved memory leak detection for your Activities and Fragments when using Profilers.