本文介绍了Android Logcat中GC_FOR_MALLOC、GC_EXPLICIT等GC_*是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果您查看 Android 日志,您可能会看到很多这样的内容.

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.

示例:

 28470               dalvikvm  D  GC_FOR_MALLOC freed 665 objects / 239992 bytes in 71ms
 28470               dalvikvm  D  GC_FOR_MALLOC freed 673 objects / 240288 bytes in 87ms
 21940               dalvikvm  D  GC_EXPLICIT freed 4802 objects / 185320 bytes in 78ms
 28470               dalvikvm  D  GC_FOR_MALLOC freed 666 objects / 240536 bytes in 63ms

推荐答案

GC_FOR_MALLOC 表示由于堆上没有足够的内存来执行分配而触发了 GC.可能在创建新对象时触发.

GC_FOR_MALLOC means that the GC was triggered because there wasn't enough memory left on the heap to perform an allocation. Might be triggered when new objects are being created.

GC_EXPLICIT 表示已明确要求垃圾收集器进行收集,而不是由堆中的高水位线触发.到处都会发生,但最有可能发生在线程被终止或绑定器通信被取消时.

GC_EXPLICIT means that the garbage collector has been explicitly asked to collect, instead of being triggered by high water marks in the heap. Happens all over the place, but most likely when a thread is being killed or when a binder communication is taken down.

还有其他一些:

GC_CONCURRENT 当堆达到一定数量的要收集的对象时触发.

GC_CONCURRENT Triggered when the heap has reached a certain amount of objects to collect.

GC_EXTERNAL_ALLOC 表示 VM 正在尝试减少用于可收集对象的内存量,以便为更多不可收集对象腾出空间.

GC_EXTERNAL_ALLOC means that the the VM is trying to reduce the amount of memory used for collectable objects, to make room for more non-collectable.

更新:在更高版本的 Android 中,第一个事件的名称发生了变化.它现在被称为GC_FOR_ALLOC".还有一个新事件可用,尽管在现代手机中非常罕见:GC_BEFORE_OOM 表示系统运行内存非常低,并且执行了最终 GC,以避免调用低内存杀手.

Update: There has been a name-change of the first event in later versions of Android. It's now called "GC_FOR_ALLOC".There is also a new event available, although very rare in modern phones:GC_BEFORE_OOM means that the system is running really low on memory, and that there is a final GC performed, in order to avoid calling the low memory killer.

这篇关于Android Logcat中GC_FOR_MALLOC、GC_EXPLICIT等GC_*是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 00:41
查看更多