What does GC_FOR_MALLOC, GC_EXPLICIT and other GC_ * mean in Android Logcat?

If you see Android logs, you can see a lot of such things.

What do they mean, knowing that this can help us improve memory allocation.

Example:

28470 dalvikvm D GC_FOR_MALLOC freed 665 objects / 239992 bytes in 71ms 28470 dalvikvm D GC_FOR_MALLOC freed 673 objects / 240288 bytes in 87ms 21940 dalvikvm D GC_EXPLICIT freed 4802 objects / 185320 bytes in 78ms 28470 dalvikvm D GC_FOR_MALLOC freed 666 objects / 240536 bytes in 63ms 
+61
garbage-collection android logcat
Feb 12 '11 at 5:41
source share
3 answers

GC_FOR_MALLOC means that GC was called because there was not enough memory left in the heap to perform the allocation. May work when creating new objects.

GC_EXPLICIT means that the garbage collector explicitly asked to collect instead of being run with watermarks on the heap. It happens everywhere, but most likely when a thread is killed or when a bond is bound.

There are several others:

GC_CONCURRENT Starts when the heap reaches a certain number of objects to collect.

GC_EXTERNAL_ALLOC means that the virtual machine is trying to reduce the amount of memory used for collected objects in order to free up space for more non-assembled ones.

Update: Change the name of the first event in later versions of Android. Now it is called "GC_FOR_ALLOC". There is also a new event, although it is very rare in modern phones: GC_BEFORE_OOM means that the system runs at the lowest level in memory and that the final GC is executed to avoid calling a low-memory killer.

+123
Feb 12 2018-11-12T00:
source share

Another place where Dalvik garbage collector messages are explained is in this video: Google I / O 2011: memory management for Android apps

After about 14 minutes in the presentation, he breaks down the message format. (By the way, this video has really good information about debugging memory leaks)

Roughly speaking, the format is [Reason] [Amount Freed], [Heap Statistics], [External Memory Statistics], [Pause Time]

Cause

Robert / yuku has already given information on the meaning of these.

Quantity Released

eg. freed 2125K

Self catering

Heap Statistics

eg. 47% free 6214K/11719K

These numbers reflect conditions after the start of the GC. "47% free" and 6,214 thousand. Reflect the current use of the heap. 11719K represents the total heap size. From what I can tell, the heap can grow / shrink, so you will not necessarily have an OutOfMemoryError if you click on this limit.

External Memory Statistics

For example, external 7142K/8400K

Note. This can only exist in versions of Android prior to the cellular version (up to 3.0).

Before Honeycomb, bitmaps are allocated outside your virtual machine (for example, Bitmap.createBitmap () allocates a bitmap from the outside and allocates only a few tens of bytes on your local heap). Other examples of external distributions for java.nio.ByteBuffers.

Pause time

If this is a parallel GC event, it will be indicated twice. One of them is to pause before the GC, one is to pause when the GC is mostly executed. For example. paused 3ms+5ms

For non-competitive GC events, there is only one pause time, and it is usually much longer. For example. paused 87ms

+35
Aug 03 2018-11-21T00:
source share

I also found this in Android sources, dalvik/vm/alloc/Heap.h Let it be useful.

 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; 
+25
Jun 13 '11 at 10:32
source share



All Articles