We are all used to seeing lines like “D/dalvikvm( 8285): GC_CONCURRENT freed 494K, 9% free 14648K/16071K, paused 2ms+2ms” in the logcat, but what does the types mean (why is the device Garbage collecting just then)?
From the sources “dalvik/vm/alloc/Heap.h” we find that
typedef enum {
/* Not enough space for an "ordinary" Object to be allocated. */
GC_FOR_MALLOC,
/* Automatic GC triggered by exceeding a heap occupancy threshold. */
GC_CONCURRENT,
/* Explicit GC via Runtime.gc(), VMRuntime.gc(), or SIGUSR1. */
GC_EXPLICIT,
/* GC to try to reduce heap footprint to allow more non-GC'ed memory. */
GC_EXTERNAL_ALLOC,
/* GC to dump heap contents to a file, only used under WITH_HPROF */
GC_HPROF_DUMP_HEAP
} GcReason; |
typedef enum {
/* Not enough space for an "ordinary" Object to be allocated. */
GC_FOR_MALLOC,
/* Automatic GC triggered by exceeding a heap occupancy threshold. */
GC_CONCURRENT,
/* Explicit GC via Runtime.gc(), VMRuntime.gc(), or SIGUSR1. */
GC_EXPLICIT,
/* GC to try to reduce heap footprint to allow more non-GC'ed memory. */
GC_EXTERNAL_ALLOC,
/* GC to dump heap contents to a file, only used under WITH_HPROF */
GC_HPROF_DUMP_HEAP
} GcReason;
And a slightly more expanded explanation is:
GC_FOR_MALLOC was triggered because there wasn’t enough memory left on the heap to perform an allocation.
GC_EXPLICIT means that the garbage collector has been explicitly asked to collect.
GC_CONCURRENT Is triggered when the heap has reached a certain amount of objects to collect.
GC_EXTERNAL_ALLOC is triggered when the VM is trying to reduce the amount of memory used for collectable objects, to make room for more non-collectable.