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

前端 未结 3 1327
野的像风
野的像风 2020-11-27 10:11

If you see the Android logs, you may see a lot of those things.

What do they mean, knowing those may help us doing better memory allocations.

Example:

<
3条回答
  •  甜味超标
    2020-11-27 10:43

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

    At about 14 minutes into the presentation, he breaks down the message format. (BTW, that video has really good info on debugging memory leaks)

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

    Reason

    Robert/yuku already gave info on the meaning of these.

    Amount Freed

    E.g. freed 2125K

    Self explanatory

    Heap Statistics

    E.g. 47% free 6214K/11719K

    These numbers reflect conditions after the GC ran. The "47% free" and 6214K reflect the current heap usage. The 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 hit this limit.

    External Memory Statistics

    E.g external 7142K/8400K

    Note: This might only exist in pre-Honeycomb versions of Android (pre 3.0).

    Before Honeycomb, bitmaps are allocated external to your VM (e.g. Bitmap.createBitmap() allocates the bitmap externally and only allocates a few dozen bytes on your local heap). Other examples of external allocations are for java.nio.ByteBuffers.

    Pause Time

    If it's a concurrent GC event, there will be two times listed. One is for a pause before the GC, one is for a pause when the GC is mostly done. E.g. paused 3ms+5ms

    For non-concurrent GC events, there is only one pause time and it's typically much bigger. E.g. paused 87ms

提交回复
热议问题