Android 内存溢出的几点解决方法
来源:互联网 发布:linux应用程序开发详解 编辑:程序博客网 时间:2024/05/16 18:58
前言:
垃圾回收的几种情况:
GC_FOR_MALLOC means that the GC was triggered because there wasn'tenough memory left on the heap to perform an allocation. Might betriggered when new objects are beingcreated.
GC_EXPLICIT means that the garbage collector has been explicitlyasked to collect, instead of being triggered by high water marks inthe heap. Happens all over the place, but most likely when a threadis being killed or when a binder communication is takendown.
There are a few others as well:
GC_CONCURRENT Triggered when the heap has reached a certain amountof objects to collect.
GC_EXTERNAL_ALLOC means that the the VM is trying to reduce theamount of memory used for collectable objects, to make room formorenon-collectable.
中文理解(Copy的)
- GC_MALLOC, 内存分配失败时触发
- GC_CONCURRENT,当分配的对象大小超过384K时触发
- GC_EXPLICIT,对垃圾收集的显式调用(System.gc)
- GC_EXTERNAL_ALLOC,外部内存分配失败时触发
freed 199K表示本次垃圾收集释放了199K的内存,
53% free3023K/6343K,其中6343K表示当前内存总量,3023K表示可用内存,53%表示可用内存占总内存的比例。
external 0K/0K,表示可用外部内存/外部内存总量
paused
2ms+2ms,第一个时间值表示markrootset的时间,第二个时间值表示第二次mark的时间。如果触发原因不是GC_CONCURRENT,这一行为单个时间值,表示垃圾收集的耗时时间。
调用垃圾回收的原因:
typedefenum{
}GcReason;
垃圾回收调试信息解读(就是LogCat中那些GC信息):
Roughly speaking, the format is [Reason] [Amount Freed],[Heap Statistics], [External Memory Statistics], [PauseTime]
Reason
Robert/yuku already gave info on the meaning of these.
Amount Freed
E.g. freed 2125K
Self explanatory
Heap Statistics
E.g. 47% free 6214K/11719K
These numbers reflect conditions after the GC ran. The "47%free" and 6214K reflect the current heap usage. The 11719Krepresents the total heap size. From what I can tell, the heap cangrow/shrink, so you will not necessarily have an OutOfMemoryErrorif you hit this limit.
External Memory Statistics
E.g external 7142K/8400K
Note: This might only exist in pre-Honeycomb versions of Android(pre 3.0).
Before Honeycomb, bitmaps are allocated external to your VM(e.g. Bitmap.createBitmap() allocates the bitmap externally andonly allocates a few dozen bytes on your local heap). Otherexamples of external allocations are for java.nio.ByteBuffers.
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 ismostly done. E.g. paused 3ms+5ms
For non-concurrent GC events, there is only one pause time andit""s typically much bigger. E.g. paused 87ms
解决方法:
第一种:
android不同设备单个进程可用内存是不一样的,可以查看/system/build.prop文件。
# This is a high density device with more memory, so larger vmheaps for it.
dalvik.vm.heapsize=24m
上面heapsize参数表示单个进程可用的最大内存,单如果存在如下参数:
dalvik.vm.heapgrowthlimit=16m
largeheaplimit参数表示单个进程内存被限定在16m,即程序运行过程中实际只能使用16m内存,不过有一个办法可以解决,编辑AndroidManifest.xml中的Application节点,增加属性largeheap="true"参数.
第二种:
第三种:
privatefinal static floatTARGET_HEAP_UTILIZATION =0.75f;
VMRuntime.getRuntime().setTargetHeapUtilization
这种是修改内存使用率,在系统GC的时候可以尽量提高回收的效率。
- Android 内存溢出的几点解决方法
- Android 内存优化的几点知识
- Tomcat内存溢出的几点方案
- 内存溢出的几点原因
- Android内存溢出的解决方法
- Android内存溢出的解决方法
- Android内存溢出的解决方法
- android内存溢出的解决方法
- android内存溢出的解决方法
- Android内存溢出的解决方法
- android内存溢出的解决方法总结
- android内存溢出的解决方法(转)
- Android Context的几点看法
- Java常见的几种内存溢出及解决方法
- Java常见的几种内存溢出及解决方法
- Java常见的几种内存溢出及解决方法
- Java常见的几种内存溢出及解决方法
- Java常见的几种内存溢出及解决方法
- Android 获取系统相册里的照片及缩略图
- acfun json 弹幕 转换 bilibili xml 弹幕
- 编写高效的android代码(译文)
- TIGASE 开发纪录一tigase的搭建
- Android 内存优化的几点知识
- Android 内存溢出的几点解决方法
- 关于return和finally
- Android NFC开发读写NDEF数据实例
- Android 编程规范
- 程序不报错但无法运行
- 【Java】打印一个0到1之间的实数的二进制表示
- JFreeChart画图示例
- Rotate Image
- Android 混淆导包APK时报错