Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Understanding Android GC Messages

I have the following message on my catlog,

GC_CONCURRENT freed 456K, 19% free 2753K/3360K, paused 5ms+9ms, total 378ms

I am trying to make sense of the last value total. I've checked other GC related question on the site they either have two pauses associated with the concurrent GC or a single total pause for the non concurrent GC. Why do i have two? Did my app paused for 5+9 ms or 378 ms? What exactly is total?

like image 297
Suleymanoglu Naim Avatar asked Apr 03 '13 11:04

Suleymanoglu Naim


People also ask

How GC works in Android?

If your app creates a lot of objects, then the Android run time (ART) environment will trigger garbage collection (GC) frequently. Android garbage collection is an automatic process which removes unused objects from memory. However, frequent garbage collection consumes a lot of CPU, and it will also pause the app.

Can you manually call the garbage collector Android?

Generally speaking, in the presence of a garbage collector, it is never good practice to manually call the GC. A GC is organized around heuristic algorithms which work best when left to their own devices. Calling the GC manually often decreases performance.


2 Answers

Don't have a definitive answer, but from what I get, GC_CONCURRENT is a garbage collection that runs in a separate thread. This means that while it might take a total of X ms (378 in your case) to run, your actual running thread will not be blocked for that long. It will only be blocked a bit at the beginning and at the end of the concurrent garbage collection process (5+9=14ms in your example)

This type of garbage collection is auto-triggered by the JVM when it decides it's a good time to do that (usually when the heap has grown dangerously high). Other types of GC, like GC_EXPLICIT (if I'm not mistaking on the name) is triggered when you do a

System.gc();

in your code. For this type of garbage collection it will only report one time (like Y ms) and in this case your thread will actually be blocked for that amount of time until this type of GC process finishes.

like image 123
Shivan Dragon Avatar answered Oct 11 '22 08:10

Shivan Dragon


GC_CONCURRENT: Triggered when the heap is growing. So it can reclaim memory in time so the heap doesn't need to be enlarged

GC_CONCURRENT freed 456K

This part tells you how much memory was freed by this GC sweep

GC_CONCURRENT freed 456K, 19% free 2753K/3360K

This part tells how much % of the heap is free, the size of the alive objects and the total size of the heap. So in the above example the 19% free, there is 2753Kmemory in use and the total heap size is 3360K.

The last part of the log tells you how long the GC took. on a GC_CONCURRENT collection you will see 2 times. one at the beginning of the collection, and one at the end.

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

Source:

https://sites.google.com/site/pyximanew/blog/androidunderstandingddmslogcatmemoryoutputmessages

Another place where things are explained clearly...

http://www.youtube.com/watch?v=_CruQY55HOk

like image 33
Thalaivar Avatar answered Oct 11 '22 08:10

Thalaivar