Android内存使用——垃圾回收LOG,GC_CONCURRENT等的意义的说明(有用)
来源:互联网 发布:软件编程自学网站 编辑:程序博客网 时间:2024/05/01 04:04
D/dalvikvm: <GC_Reason> <Amount_freed>, <Heap_stats>, <External_memory_stats>, <Pause_time>
每隔一段时间,系统回收器都会打印内存回收的情况。日志的内容格式就是上面那条格式。下面是详细说明
<回收原因><回收内存总数><可用内存百分比><外部内存状态><回收占用时间>
D/dalvikvm( 9050): GC_CONCURRENT freed 2049K, 65% free 3571K/9991K, external 4703K/5261K, paused 2ms+2ms
GC Reason GC回收原因(是什么触发了回收,回收的类型是什么)包含以下类型
GC_CONCURRENT 并发回收
在你的程序堆栈将达到最大值的时候,并发的回收内存。
GC_FOR_MALLOC 分配时回收
如果你的程序请求内存但此时堆栈已经是满了,这样的话系统会停止你的程序并回收内存。
GC_HPROF_DUMP_HEAP 当你创建HPROF文件分析内存堆栈的时候。
GC_EXPLICIT 精确释放
程序中明确要求回收内存,比如调用gc(最好避免主动调用应当相信回收器会自动在需要的时候回收内存的)
GC_EXTERNAL_ALLOC
This happens only on API level 10 and lower (newer versions allocate everything in the Dalvik heap). A garbage collection for externally allocated memory (such as the pixel data stored in native memory or NIO byte buffers).
Amount freed
回收内存总数
回收器回收的内存总数。
Heap stats
可用内存百分比
可用内存百分比=100%-已用内存/可用内存
外部内存状态
只有API 10或以下的设备才会有。已分配内存/可分用内存总数
Pause time
回收占用时间
越大的内存堆栈回收需要的时间越长。并发释放时间有两个一个是回收开始时,一个是接近完成时的时间。
每隔一段时间,系统回收器都会打印内存回收的情况。日志的内容格式就是上面那条格式。下面是详细说明
<回收原因><回收内存总数><可用内存百分比><外部内存状态><回收占用时间>
D/dalvikvm( 9050): GC_CONCURRENT freed 2049K, 65% free 3571K/9991K, external 4703K/5261K, paused 2ms+2ms
GC Reason GC回收原因(是什么触发了回收,回收的类型是什么)包含以下类型
GC_CONCURRENT 并发回收
在你的程序堆栈将达到最大值的时候,并发的回收内存。
GC_FOR_MALLOC 分配时回收
如果你的程序请求内存但此时堆栈已经是满了,这样的话系统会停止你的程序并回收内存。
GC_HPROF_DUMP_HEAP 当你创建HPROF文件分析内存堆栈的时候。
GC_EXPLICIT 精确释放
程序中明确要求回收内存,比如调用gc(最好避免主动调用应当相信回收器会自动在需要的时候回收内存的)
GC_EXTERNAL_ALLOC
This happens only on API level 10 and lower (newer versions allocate everything in the Dalvik heap). A garbage collection for externally allocated memory (such as the pixel data stored in native memory or NIO byte buffers).
Amount freed
回收内存总数
回收器回收的内存总数。
Heap stats
可用内存百分比
可用内存百分比=100%-已用内存/可用内存
外部内存状态
只有API 10或以下的设备才会有。已分配内存/可分用内存总数
Pause time
回收占用时间
越大的内存堆栈回收需要的时间越长。并发释放时间有两个一个是回收开始时,一个是接近完成时的时间。
在调试程序的时候,经常发现GC_CONCURRENT之类的打印。在网上搜了一下,感觉说法各式各样。最后,在Google的官方网站上发现了详细介绍。
Every time a garbage collection occurs, logcat prints a message with the following information:
D/dalvikvm: <GC_Reason> <Amount_freed>, <Heap_stats>, <External_memory_stats>, <Pause_time>- GC Reason
- What triggered the garbage collection and what kind of collection it is. Reasons that may appearinclude:
GC_CONCURRENT
- A concurrent garbage collection that frees up memory as your heap begins to fill up.
GC_FOR_MALLOC
- A garbage collection caused because your app attempted to allocate memory when your heap wasalready full, so the system had to stop your app and reclaim memory.
GC_HPROF_DUMP_HEAP
- A garbage collection that occurs when you create an HPROF file to analyze your heap.
GC_EXPLICIT
- An explicit garbage collection, such as when you call
gc()
(which youshould avoid calling and instead trust the garbage collector to run when needed). GC_EXTERNAL_ALLOC
- This happens only on API level 10 and lower (newer versions allocate everything in the Dalvikheap). A garbage collection for externally allocated memory (such as the pixel data stored innative memory or NIO byte buffers).
- Amount freed
- The amount of memory reclaimed from this garbage collection.
- Heap stats
- Percentage free and (number of live objects)/(total heap size).
- External memory stats
- Externally allocated memory on API level 10 and lower (amount of allocated memory) / (limit atwhich collection will occur).
- Pause time
- Larger heaps will have larger pause times. Concurrent pause times show two pauses: one at thebeginning of the collection and another near the end.
For example:
D/dalvikvm( 9050): GC_CONCURRENT freed 2049K, 65% free 3571K/9991K, external 4703K/5261K, paused 2ms+2ms来源: <http://developer.android.com/tools/debugging/debugging-memory.html#LogMessages>
GC Reason:引起GC回收的原因。包括a)GC_CONCURRENT:我的理解是当你的堆快被用完的时候,就会触发这个GC回收。b)堆已经满了,同时又要试图分配新的内存,所以系统要回收内存。c)GC_HPROF_DUMP_HEAP这是做HPROF分析用的,正常情况下不会有的。d)这个是明确调用gc产出的垃圾回收。e)GC_EXTERNAL_ALLOC这个在2.3版本以后已经废弃了。所以不用关心了。
Amount freed:本次垃圾回收释放出来的内存。
Heap stats:当前空闲内存占总内存的百分比。比如下面的例子总的65%就是说有65%的空闲。二后面的3571K是占用了这么多,9991K是总的内存。这两个值相除,就是占用的百分比,加上前面的65%正好是100%。
External memory stats:2.3之后就废弃了。
Pause time:你的应用暂停的时间。
假如3571K/9991K 这个值不断增加,从来不减少,则可能有内存泄漏的问题。
0 0
- Android内存使用——垃圾回收LOG,GC_CONCURRENT等的意义的说明(有用)
- Android内存使用——垃圾回收LOG,GC_CONCURRENT等的意义的说明
- Android内存使用——垃圾回收LOG,GC_CONCURRENT等的意义的说明
- gc垃圾回收的一些含义gc_concurrent gcformalloc
- 【Developer Log】Java的内存使用、垃圾回收和内存泄漏
- Java的内存回收——垃圾回收机制
- Android的垃圾回收与内存泄露
- C++的垃圾回收——以对象管理内存
- 控制系统垃圾回收器(一种自动回收未使用内存的服务)。
- Java内存回收(2)——垃圾回收算法
- 简析Android的垃圾回收与内存泄露
- 简析Android的垃圾回收与内存泄露
- 简析Android的垃圾回收与内存泄露
- 简析Android的垃圾回收与内存泄露
- android内存管理,垃圾回收策略的疑惑
- android内存管理,垃圾回收策略的疑惑
- 简析Android的垃圾回收和内存泄漏
- Android的垃圾回收机制
- iOS带有勾选框的提示框(封装代码)
- Android Launcher分析和修改4——初始化加载数据
- C# Activex开发、打包、签名、发布(转)
- Path Sum (leetcode)
- IOS7 8中tableview分割线缺少15像素
- Android内存使用——垃圾回收LOG,GC_CONCURRENT等的意义的说明(有用)
- AssetBundle杂谈
- CSharp学习视频分享与开发技术QQ交流群
- 第十一周 项目六:回文数
- CocoaPods详解之----制作篇
- quartz 动态添加任务、暂停、删除
- CoreText使用
- struts2 返回json数据
- C++中的访问权限控制