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
-
3Just fyi, since it refers to the topic - there's a new blog post on the android blog on mem analysis: http://android-developers.blogspot.com/2011/03/memory-analysis-for-android.html – Mathias Conradt Mar 25 '11 at 03:36
3 Answers
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.

- 73,164
- 16
- 126
- 119
-
Ok so i clicked dump, and it opened a new window named android123123123 with lots of weird characters in it. What do i do with this page? Where is the file? Thanks again – aryaxt Jun 24 '10 at 18:48
-
2I figured it out myself. File ==> Save As, then opened the file in memory analyzer – aryaxt Jun 24 '10 at 18:58
-
6You omitted a key step mentioned in Mathias's answer: "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." – Jeff Axelrod Jul 24 '12 at 16:55
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()
.

- 28,420
- 21
- 138
- 192
-
I'm on mac there is no such a thning as exe, and i didn't have to do anything with the file, I simply saved it as it was from eclipse, and i opened it with memory analyzer, with no problem – aryaxt Jun 24 '10 at 23:06
-
1@MathiasLin, is there any way to analyze/view objects in the native heap? – snapfractalpop Apr 04 '12 at 03:02
-
@snapfractalpop sorry, i don't know, haven't looked for such yet myself. – Mathias Conradt Apr 04 '12 at 09:50
-
@snapfractalpop did you find a way to analyze objects in native memory? – Harshal Kshatriya Jun 15 '12 at 09:08
-
@HarshalKshatriya, sorry I have not.. but if you ever learn how, I'd love to know! – snapfractalpop Jun 19 '12 at 14:43
-
(Standalone) DDMS has a 'native heap' tab to analyze it;
/tools/ddms – Mathias Conradt Jun 19 '12 at 14:58 -
@snapfractalpop If I learn about it, sure. Mathias, I'll try it out. – Harshal Kshatriya Jun 20 '12 at 12:40
-
You no longer need to convert heap dump if you have the eclipse version of MAT. – Daniel Ryan Oct 07 '12 at 23:34
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

- 627
- 2
- 7
- 14