Java 获取 I/art:显式并发标记清除 GC 释放
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35341435/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Getting I/art: Explicit concurrent mark sweep GC freed
提问by Jaeger
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
日志 : 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 ) .
它只是扫描SD卡中MyData中的文件,其中包含一堆图片(约20张图片)。
**Scan = Getting the pics names and saving them to String .
**Scan = 获取图片名称并将它们保存到 String 。
采纳答案by Bryan Herbst
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.
每次我们遇到这个循环时,我们都会分配一百个新的 Bitmap 对象。
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.
防止 GC 清除的最佳方法是不分配对象。当然,您必须在 Java 中分配对象,因此您需要确保没有进行不必要的分配。
Here is one of many YouTube videosthat Google has release with tips on avoiding GC events and managing memory properly.
这是Google 发布的众多 YouTube 视频之一,其中包含有关避免 GC 事件和正确管理内存的提示。