Android ==> 内存分析 ==> Eclipse 内存分析器?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3112671/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 08:45:00  来源:igfitidea点击:

Android ==> Memory Analysing ==> Eclipse memory analyzer?

androideclipseheap-dumpmemoryanalyzer

提问by aryaxt

I need to check my application for memory leaks, i also need to see the memory allocation of my application. I downloaded and installed eclipse memory analyzer, and it looks like the first step is to open a heap dump. But what is a heap dump, how can i create a heap dump. And how exactly am i going to use this software, I did some googling but i couldn't find any useful information thanks

我需要检查我的应用程序是否存在内存泄漏,我还需要查看我的应用程序的内存分配。我下载并安装了eclipse内存分析器,看起来第一步是打开heap dump。但是什么是堆转储,我如何创建堆转储。我到底要如何使用这个软件,我做了一些谷歌搜索,但我找不到任何有用的信息,谢谢

采纳答案by Robby Pond

When you debug your app, open DDMSin Eclipse. On the toolbar there is a heap dump button that you can use to generate a heap dump to view in Eclipse memory analyzer. This is only supported I think with the 1.6+ or 2.0+ SDK.

调试应用程序时,请在 Eclipse 中打开DDMS。在工具栏上有一个堆转储按钮,您可以使用它生成堆转储以在 Eclipse 内存分析器中查看。我认为仅支持 1.6+ 或 2.0+ SDK。

回答by Mathias Conradt

The heap dump of the dalvik VM needs to be converted to regular hprof format using the hprof-conv.exe converter tool in the tools directory of the Android SDK. You can open this hprof with Eclipse MAT or other tools are: YourKit http://www.yourkit.com/and JProbe http://www.quest.com/jprobe/

dalvik VM的heap dump需要使用Android SDK的tools目录下的hprof-conv.exe转换工具转换成常规的hprof格式。您可以使用 Eclipse MAT 或其他工具打开此 hprof:YourKit http://www.yourkit.com/和 JProbe http://www.quest.com/jprobe/

Beside DDMS you can also create the hprof from you app/code (only newer SDKs) via Debug.dumpHprofData(...)

除了 DDMS,您还可以通过以下方式从您的应用程序/代码(仅限较新的 SDK)创建 hprof Debug.dumpHprofData(...)

Note that in DDMS you can see the heap that your app is using. It doesn't show the native heap that external resources such as bitmaps are allocating. Nevertheless, these resources also need to be taken into account when checking for memory leaks. When both native and app heap adds up to 16MB / resp. 24MB you will get an OOM error.

请注意,在 DDMS 中,您可以看到您的应用程序正在使用的堆。它不显示外部资源(如位图)正在分配的本机堆。尽管如此,在检查内存泄漏时也需要考虑这些资源。当本机和应用程序堆加起来为 16MB/resp 时。24MB 你会得到一个 OOM 错误。

You can see the native heap that's been used (i.e. by bitmaps in your app) via Debug.getNativHeapAllocatedSize().

您可以通过Debug.getNativHeapAllocatedSize().

回答by Johan Norén

Also see http://developer.android.com/guide/developing/debugging/ddms.html#profiling

另请参阅http://developer.android.com/guide/developing/debugging/ddms.html#profiling

If it helps, you can enable profiling over local areas of code by using the Debug API. In that way you have less verbosity when analysing the traces in for example traceview. See http://macgyverdev.blogspot.com/2011/07/profiling-android-application-tutorial.htmlfor examples.

如果有帮助,您可以使用 Debug API 启用对本地代码区域的分析。这样,在分析例如 traceview 中的跟踪时,您就可以减少冗长。有关示例,请参阅http://macgyverdev.blogspot.com/2011/07/profiling-android-application-tutorial.html

And some more detailed info on how to convert DDMS heap dumps so you can view them in Eclipse Memory Analyzer and find your leaking objects via the dominator tree tooling: http://macgyverdev.blogspot.com/2011/11/android-track-down-memory-leaks.html

还有一些关于如何转换 DDMS 堆转储的更详细信息,以便您可以在 Eclipse 内存分析器中查看它们并通过支配树工具找到泄漏的对象:http: //macgyverdev.blogspot.com/2011/11/android-track-内存泄漏.html