The sun JVM supports a -XX:+HeapDumpOnOutOfMemoryError option to dump heap whenever a java process runs out of heap.
Is there a similar option on Android that will make an android app dump heap on an OutOfMemoryException? It can be difficult to try to time it properly when using DDMS manually.
To expand upon CommonsWare’s answer:
I followed his suggestion successfully in my own Android app with the following code:
After the dump is created, you need to copy it from your phone to your PC: Click “Turn on USB storage” on the phone, find the file and copy it to your hard drive.
Then, if you want to use the Eclipse Memory Analyzer (MAT) to analyze the file, you will need to covert the file:
hprof-conv.exe dump.hprof dump-conv.hprof(hprof-conv is located underandroid-sdk/tools)Finally, open the
dump-conv.hproffile with MAT