Getting I/art: Explicit concurrent mark sweep GC freed

橙三吉。 提交于 2019-12-31 10:39:11

问题


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 .


回答1:


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.



来源:https://stackoverflow.com/questions/35341435/getting-i-art-explicit-concurrent-mark-sweep-gc-freed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!