Android内存使用——垃圾回收LOG,GC_CONCURRENT等的意义的说明
16lz
2021-01-25
在调试程序的时候,经常发现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 appear include:
-
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 was already 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 you should 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 Dalvik heap). A garbage collection for externally allocated memory (such as the pixel data stored in native 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 at which collection will occur).
- Pause time
- Larger heaps will have larger pause times. Concurrent pause times show two pauses: one at the beginning 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 这个值不断增加,从来不减少,则可能有内存泄漏的问题。
更多相关文章
- "0x0055cde3"指令引用的内存"0x0000ffff"
- Android(安卓)系统信息(内存、cpu、sd卡、电量、版本)获取
- Android(安卓)MemInfo 各项的意义(转)
- [转]android out of memory(OOM)
- LeakCanary 的使用介绍
- The Android(安卓)ION memory allocator
- 给android虚拟机加内存
- Android(安卓)SdCard 新建文件夹并在文件夹中读、写文件
- android内存溢出的解决方法(转)