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 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.
There are a few others as well:
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{
/* 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;
GC_EXTERNAL_ALLOC freed 297K, 49% free 3411K/6663K, external 24870K/26260K, paused 83ms
前面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://hi.baidu.com/qmiao128/blog/item/69f2fa31d4a5d3b05fdf0ed2.html
分享到:
相关推荐
实现自己的mem_malloc和mem_free
通过C语言实现 malloc 申请内存 清除内存等操作
ics课程第九章实现动态内存分配,最后得了86分,实在不想改了
csapp 实验 这是csapp实验中的第三个系列,有关malloc 的改写,就发了有用的
lunix下用c编写malloc函数
以class类的形式实现对程序内存泄露的支持
format_mallocdebug_op.ksh mallocdebug后格式化输出堆栈日志
Implementation of malloc-based buffers to store data that can t be processed by the hardware.
umm_malloc-小型微处理器的内存管理器 这是专门设计用于ARM7嵌入式处理器的内存管理库,但它应可在许多其他32位处理器以及16和8位设备上使用。 您甚至可以在较大的项目中使用它,在该项目中单个进程可能要管理大量...
stm32f407实现内存管理malloc功能
提供源码和设计文档
高效的内存管理功能,有效避免内存碎片,快捷、高效是主要特点
Nu_LB_NUC140_Malloc.rar Nu_LB_NUC140板子上面简单的Malloc函数遇到问题,写的测试代码
从uclibc的malloc和glib的glist、timeout提取出来的代码,用于嵌入式开发。分配一块内存用于动态内存,有定时功能,提供双向链表这种容器。用于没有操作系统和c标准库支持的环境。
嵌入式系统下内存泄漏检查库函数mTrace以及测试代码,有详细使用文档.这个是将malloc和free 函数控制起来,检查内存.
SIP协议栈高层API EXOSIP的API说明文档该文档详细说明了如何使用EXOSIP库的函数来实现注册,呼叫,应答,挂机等电话流程
my_malloc:自己动手写的malloc函数.希望对大家了解内存管理有所帮助
包括用CUBE驱动LCD屏,用SPI写FLASH,MALLOC文件的移植,SDIO驱动TF卡,FATFS管理SD卡或外部SRAM。移植过程及其艰辛,踩过无数坑,终于调试成功。全部程序用的都是HAL库。还有自己写的文档说明,记录了一些经验与...
malloc_free.exe
源程序说明本实验对应 1_kernel_mem_malloc系 统 依 赖#define RT_USING_HEAP此项可选,开启此项可以创建动态线程和动态信号