gc垃圾回收的一些含义gc_concurrent gcformalloc

本文详细解释了Android系统中垃圾回收(GC)日志的各项指标,包括GC原因、释放内存量、堆内存状态等,并提供了如何判断应用程序是否存在内存泄漏的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >



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 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 这个值络续增长,从来不削减,则可能有内存泄漏的题目。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值