Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting I/art: Explicit concurrent mark sweep GC freed

I'm starting a service => background service, And starting a check for files in "new Thread", In the log i'm getting the following, the service/app gets paused .

Log : I/art: Explicit concurrent mark sweep GC freed 25935(1686KB) AllocSpace objects, 13(903KB) LOS objects, 39% free, 13MB/22MB, paused 649us total 43.569ms

It's just a scan for files in MyData in SDcard, which contain a bunch of pics ( about 20 pics ) .

**Scan = Getting the pics names and saving them to String .

like image 227
Jaeger Avatar asked Feb 11 '16 14:02

Jaeger


1 Answers

All this means is that the garbage collector is doing its job and freeing up memory.

If you are seeing this frequently (or consistently), then you are likely allocating too many objects. A common cause is allocating many (or a few large) objects within a loop like so:

for (int i = 0; i < 100; i++) {
    Bitmap bmp = Bitmap.create(100, 100, Bitmap.Config.ARGB_4444);
}

Every time we hit this loop, we allocate one hundred new Bitmap objects.

The best way to prevent GC sweeps is to not allocate objects. Of course you have to allocate objects in Java, so you need to ensure that you are not allocating unnecessarily.

Here is one of many YouTube videos that Google has release with tips on avoiding GC events and managing memory properly.

like image 60
Bryan Herbst Avatar answered Nov 20 '22 08:11

Bryan Herbst