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.html
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.java
There are a few others as well:app
GC_CONCURRENT Triggered when the heap has reached a certain amount of objects to collect.線程
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.調試
typedefenum{
GC_FOR_MALLOC,
GC_CONCURRENT,
GC_EXPLICIT,
GC_EXTERNAL_ALLOC,
GC_HPROF_DUMP_HEAP
}GcReason; orm
GC_EXTERNAL_ALLOC freed 297K, 49% free 3411K/6663K, external 24870K/26260K, paused 83mshtm
前面Free的內存是VM中java使用的內存,external是指VM中經過JNI中Native的類中的malloc分配出的內存,例如Bitmap和一些Cursor都是這麼分配的。
在Davilk中,給一個程序分配的內存根據機型廠商的不一樣,而不一樣,如今的大部分的是32M了,而在VM內部會把這些內存分紅java使用的內存和 Native使用的內存,它們之間是不能共享的,就是說當你的Native內存用完了,如今Java又有空閒的內存,這時Native會從新像VM申請,而不是直接使用java的。
例如上邊的例子
free 3411K/6663K和external 24870K/26260K
若是這時須要建立一個2M的Bitmap,Native現有內存26260-24870=1390K<2048k,所以他就會向Vm申請內存,雖然java空閒的內存是
6663-3411=3252>2048,但這部份內存Native是不能使用。
可是你如今去申請2M的Native內存,VM會告訴你沒法分配的,由於如今已使用的內存已經接近峯值了32M(26260+6663=32923 ),因此如今就會成force close 報OOM。因此如今咱們要檢查咱們的native內存的使用狀況來避免OOM。對象
文章轉載自:http://blog.sina.com.cn/s/blog_6610da390101bhqj.htmlblog