If you see the Android logs, you may see a lot of those things.
如果你看到Android日志,你可能会看到很多这样的东西。
What do they mean, knowing those may help us doing better memory allocations.
它们是什么意思,知道这些可能会帮助我们做更好的记忆分配。
Example:
例子:
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
3 个解决方案
#1
122
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_FOR_MALLOC意味着GC被触发,因为堆上没有足够的内存来执行分配。可能在创建新对象时触发。
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_EXPLICIT意味着已显式地要求垃圾收集器进行收集,而不是由堆中的高水印触发。这种情况随处可见,但最常见的情况是线程被杀死或绑定器通信被中断。
There are a few others as well:
还有一些其他的:
GC_CONCURRENT Triggered when the heap has reached a certain amount of objects to collect.
当堆达到要收集的对象数量时,会触发GC_CONCURRENT。
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.
GC_EXTERNAL_ALLOC表示虚拟机试图减少用于可收集对象的内存,从而为更多不可收集对象腾出空间。
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版本中,第一个事件发生了名称变化。现在被称为“GC_FOR_ALLOC”。还有一个新的事件可用,尽管在现代手机中非常罕见:GC_BEFORE_OOM意味着系统在内存上运行非常低,并且有一个最终的GC执行,以避免调用低内存杀手。
#2
35
Another place where the Dalvik garbage collector messages are explained is in this video: Google I/O 2011: Memory management for Android Apps
另一个解释Dalvik垃圾收集器消息的地方是在这个视频中:谷歌I/O 2011: Android应用的内存管理
At about 14 minutes into the presentation, he breaks down the message format. (BTW, that video has really good info on debugging memory leaks)
在演讲开始大约14分钟时,他将信息格式进行了分解。(顺便说一下,这个视频有很好的调试内存泄漏的信息)
Roughly speaking, the format is [Reason] [Amount Freed], [Heap Statistics], [External Memory Statistics], [Pause Time]
粗略地说,格式是[原因][释放的数量],[堆统计信息],[外部内存统计信息],[暂停时间]
Reason
Robert/yuku already gave info on the meaning of these.
Robert/yuku已经给出了关于这些含义的信息。
Amount Freed
E.g. freed 2125K
例如释放2125 k
Self explanatory
自我解释
Heap Statistics
E.g. 47% free 6214K/11719K
如47%免费6214 k / 11719 k
These numbers reflect conditions after the GC ran. The "47% free" and 6214K reflect the current heap usage. The 11719K represents the total heap size. From what I can tell, the heap can grow/shrink, so you will not necessarily have an OutOfMemoryError if you hit this limit.
这些数字反映了GC运行后的情况。“47%免费”和6214K反映了当前堆的使用情况。11719K表示总堆大小。就我所知,堆可以增长/收缩,所以如果达到这个极限,您就不一定会有OutOfMemoryError。
External Memory Statistics
E.g external 7142K/8400K
E。克外部7142 k / 8400 k
Note: This might only exist in pre-Honeycomb versions of Android (pre 3.0).
注意:这可能只存在于Android (pre -蜂巢版)的前版本中。
Before Honeycomb, bitmaps are allocated external to your VM (e.g. Bitmap.createBitmap() allocates the bitmap externally and only allocates a few dozen bytes on your local heap). Other examples of external allocations are for java.nio.ByteBuffers.
在Honeycomb之前,位图被分配到VM外部(例如,位图. createbitmap()在外部分配位图,在本地堆上只分配几十个字节)。其他外部分配的例子是java.nio. bytebuffer。
Pause Time
If it's a concurrent GC event, there will be two times listed. One is for a pause before the GC, one is for a pause when the GC is mostly done. E.g. paused 3ms+5ms
如果是并发GC事件,将列出两次。一个是在GC之前暂停,另一个是在GC基本完成时暂停。如暂停3 ms + 5 ms
For non-concurrent GC events, there is only one pause time and it's typically much bigger. E.g. paused 87ms
对于非并发GC事件,只有一个暂停时间,而且通常要大得多。如暂停87毫秒
#3
26
I also found this in the Android sources, dalvik/vm/alloc/Heap.h
. May this be useful.
我还在Android源代码dalvik/vm/alloc/Heap.h中发现了这一点。可能这是有用的。
typedef enum {
/* Not enough space for an "ordinary" Object to be allocated. */
GC_FOR_MALLOC,
/* Automatic GC triggered by exceeding a heap occupancy threshold. */
GC_CONCURRENT,
/* Explicit GC via Runtime.gc(), VMRuntime.gc(), or SIGUSR1. */
GC_EXPLICIT,
/* GC to try to reduce heap footprint to allow more non-GC'ed memory. */
GC_EXTERNAL_ALLOC,
/* GC to dump heap contents to a file, only used under WITH_HPROF */
GC_HPROF_DUMP_HEAP
} GcReason;
#1
122
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_FOR_MALLOC意味着GC被触发,因为堆上没有足够的内存来执行分配。可能在创建新对象时触发。
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_EXPLICIT意味着已显式地要求垃圾收集器进行收集,而不是由堆中的高水印触发。这种情况随处可见,但最常见的情况是线程被杀死或绑定器通信被中断。
There are a few others as well:
还有一些其他的:
GC_CONCURRENT Triggered when the heap has reached a certain amount of objects to collect.
当堆达到要收集的对象数量时,会触发GC_CONCURRENT。
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.
GC_EXTERNAL_ALLOC表示虚拟机试图减少用于可收集对象的内存,从而为更多不可收集对象腾出空间。
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版本中,第一个事件发生了名称变化。现在被称为“GC_FOR_ALLOC”。还有一个新的事件可用,尽管在现代手机中非常罕见:GC_BEFORE_OOM意味着系统在内存上运行非常低,并且有一个最终的GC执行,以避免调用低内存杀手。
#2
35
Another place where the Dalvik garbage collector messages are explained is in this video: Google I/O 2011: Memory management for Android Apps
另一个解释Dalvik垃圾收集器消息的地方是在这个视频中:谷歌I/O 2011: Android应用的内存管理
At about 14 minutes into the presentation, he breaks down the message format. (BTW, that video has really good info on debugging memory leaks)
在演讲开始大约14分钟时,他将信息格式进行了分解。(顺便说一下,这个视频有很好的调试内存泄漏的信息)
Roughly speaking, the format is [Reason] [Amount Freed], [Heap Statistics], [External Memory Statistics], [Pause Time]
粗略地说,格式是[原因][释放的数量],[堆统计信息],[外部内存统计信息],[暂停时间]
Reason
Robert/yuku already gave info on the meaning of these.
Robert/yuku已经给出了关于这些含义的信息。
Amount Freed
E.g. freed 2125K
例如释放2125 k
Self explanatory
自我解释
Heap Statistics
E.g. 47% free 6214K/11719K
如47%免费6214 k / 11719 k
These numbers reflect conditions after the GC ran. The "47% free" and 6214K reflect the current heap usage. The 11719K represents the total heap size. From what I can tell, the heap can grow/shrink, so you will not necessarily have an OutOfMemoryError if you hit this limit.
这些数字反映了GC运行后的情况。“47%免费”和6214K反映了当前堆的使用情况。11719K表示总堆大小。就我所知,堆可以增长/收缩,所以如果达到这个极限,您就不一定会有OutOfMemoryError。
External Memory Statistics
E.g external 7142K/8400K
E。克外部7142 k / 8400 k
Note: This might only exist in pre-Honeycomb versions of Android (pre 3.0).
注意:这可能只存在于Android (pre -蜂巢版)的前版本中。
Before Honeycomb, bitmaps are allocated external to your VM (e.g. Bitmap.createBitmap() allocates the bitmap externally and only allocates a few dozen bytes on your local heap). Other examples of external allocations are for java.nio.ByteBuffers.
在Honeycomb之前,位图被分配到VM外部(例如,位图. createbitmap()在外部分配位图,在本地堆上只分配几十个字节)。其他外部分配的例子是java.nio. bytebuffer。
Pause Time
If it's a concurrent GC event, there will be two times listed. One is for a pause before the GC, one is for a pause when the GC is mostly done. E.g. paused 3ms+5ms
如果是并发GC事件,将列出两次。一个是在GC之前暂停,另一个是在GC基本完成时暂停。如暂停3 ms + 5 ms
For non-concurrent GC events, there is only one pause time and it's typically much bigger. E.g. paused 87ms
对于非并发GC事件,只有一个暂停时间,而且通常要大得多。如暂停87毫秒
#3
26
I also found this in the Android sources, dalvik/vm/alloc/Heap.h
. May this be useful.
我还在Android源代码dalvik/vm/alloc/Heap.h中发现了这一点。可能这是有用的。
typedef enum {
/* Not enough space for an "ordinary" Object to be allocated. */
GC_FOR_MALLOC,
/* Automatic GC triggered by exceeding a heap occupancy threshold. */
GC_CONCURRENT,
/* Explicit GC via Runtime.gc(), VMRuntime.gc(), or SIGUSR1. */
GC_EXPLICIT,
/* GC to try to reduce heap footprint to allow more non-GC'ed memory. */
GC_EXTERNAL_ALLOC,
/* GC to dump heap contents to a file, only used under WITH_HPROF */
GC_HPROF_DUMP_HEAP
} GcReason;