Sep 21

To force the garbage collector to run from adb shell, first find out the target process’ id (using e.g. ps), and then execute this in the shell (as root):

kill -10 <pid>

You should see GC_EXPLICIT in logcat:

I/dalvikvm﹕ threadid=3: reacting to signal 10
I/dalvikvm﹕ SIGUSR1 forcing GC (no HPROF)
D/dalvikvm﹕ GC_EXPLICIT freed 1K, 9% free 9250K/10112K, paused 12ms+2ms, total 60ms

Before Android 2.3, the afore would also dump the heap. On modern platforms (since Android 3.0), you can use the following, which doesn’t require root:

am dumpheap <pid> <output_file>
preload preload preload