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

人走茶凉 提交于 2019-12-05 02:48:00

When you debug your app, open DDMS in 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.

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/

Beside DDMS you can also create the hprof from you app/code (only newer SDKs) via 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.

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

Also see 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.html for examples.

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!