如何使用新的 AndroidProfiler 处理内存泄漏
How to treat memory leaks using the new AndroidProfiler
我正在尝试学习如何识别和处理我的应用程序中的内存泄漏。我正在阅读这篇文章 great article,但我对如何在 Android Studio 3.0.
附带的新 "Android Profiler" 工具中应用它感到有点困惑
我有一个测试应用程序,LeakCanary 指出我的应用程序存在内存泄漏。
事实上,当我 运行 探查器并按 "dump java heap" 时,我可以看到我的 MyCollectionActivity 有 4 个实例,当我单击这些实例时,我可以看到详细信息:
但是文章中显示的工具有我在 "Android Profiler":
中看不到的选项
I will not go into depth about how to navigate the huge memory heap.
Instead I’ll direct your attention to the Analyzer Tasks in the upper
right corner of the screenshot below. All you have to do to detect the
memory leak introduced in the example above is to check Detect Leaked
Activities and then press play to get the leaked activity to show up
under Analysis Results.
例如,在新工具中,显示泄漏实例的 "Analyzer Tasks" 和 "Analysis Results" 在哪里?
If we select the leaked activity we are presented with a Reference
Tree where the reference that is keeping the activity alive can be
identified. By looking for instances with depth zero we find that the
instance mListener located within the location manager is the reason
our activity can’t be garbage collected.
AndroidProfiler 的图像也没有显示 Reference Tree,它显示了参考,但它似乎不是很有用。
- 首先,您需要保存 堆转储。转储保存扩展名为 hprof。检查下面的附件图像以保存此文件。
- 在AndroidStudio中打开相同的文件,之后,您将能够在右上角看到Analyser Tasks选项。
我正在尝试学习如何识别和处理我的应用程序中的内存泄漏。我正在阅读这篇文章 great article,但我对如何在 Android Studio 3.0.
附带的新 "Android Profiler" 工具中应用它感到有点困惑我有一个测试应用程序,LeakCanary 指出我的应用程序存在内存泄漏。
事实上,当我 运行 探查器并按 "dump java heap" 时,我可以看到我的 MyCollectionActivity 有 4 个实例,当我单击这些实例时,我可以看到详细信息:
但是文章中显示的工具有我在 "Android Profiler":
中看不到的选项I will not go into depth about how to navigate the huge memory heap. Instead I’ll direct your attention to the Analyzer Tasks in the upper right corner of the screenshot below. All you have to do to detect the memory leak introduced in the example above is to check Detect Leaked Activities and then press play to get the leaked activity to show up under Analysis Results.
例如,在新工具中,显示泄漏实例的 "Analyzer Tasks" 和 "Analysis Results" 在哪里?
If we select the leaked activity we are presented with a Reference Tree where the reference that is keeping the activity alive can be identified. By looking for instances with depth zero we find that the instance mListener located within the location manager is the reason our activity can’t be garbage collected.
AndroidProfiler 的图像也没有显示 Reference Tree,它显示了参考,但它似乎不是很有用。
- 首先,您需要保存 堆转储。转储保存扩展名为 hprof。检查下面的附件图像以保存此文件。
- 在AndroidStudio中打开相同的文件,之后,您将能够在右上角看到Analyser Tasks选项。