Logcat不断输出GC_EXPLICIT freed 29K, 51% free 2769K/5575K, external 1649K/2078K;why?

xqhrs232 2012-05-24 10:19:10
Logcat不断输出GC_EXPLICIT freed 29K, 51% free 2769K/5575K, external 1649K/2078K;why?
...全文
1876 17 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
MR__P 2014-01-23
  • 打赏
  • 举报
回复
一般做图片加载和回收的时候会出现,这是内存回收机制在释放无用内存
吴朗 2014-01-23
  • 打赏
  • 举报
回复
引用 3 楼 xqhrs232 的回复:
GC_EXTERNAL_ALLOC freed 与 GC_EXPLICIT freed 是什么? http://www.cnblogs.com/error404/archive/2011/09/28/2194708.html

09-28 17:16:37.543: DEBUG/dalvikvm(21466): GC_EXTERNAL_ALLOC freed 390 objects / 45656 bytes in 50ms
09-28 17:16:40.513: DEBUG/dalvikvm(3267): GC_EXPLICIT freed 4501 objects / 251624 bytes in 67ms

很多做开发的朋友不明白上面这句是什么意思,给大家解释一下! 

前面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。



怎么检查native内存?
xqhrs232 2012-05-24
  • 打赏
  • 举报
回复
有些地方说这个是系统在做内存回收,我们个人做不到干涉,关键是我的系统运行久了,其它APK会被干掉----DDMS的APK列表会越来越少,像SETTING APK我就看到被干掉过一次!!!
xqhrs232 2012-05-24
  • 打赏
  • 举报
回复
有些地方说这个是系统在做内存回收,我们个人做不到干涉,关键是我的系统运行久了,其它APK会被干掉----DDMS的APK列表会越来越少,像SETTING APK我就看到被干掉过一次!!!
qthsrs232 2012-05-24
  • 打赏
  • 举报
回复
Android下怎么诊断/防止程序的内存泄漏/内存碎片,大家有没什么好方法
http://topic.csdn.net/u/20110216/09/cee0d1ae-c381-4c8f-bb8b-cbd7949ea90e.html
CNnumen 2012-05-24
  • 打赏
  • 举报
回复
代码里有调用System.gc()的语句没?
xqhrs232 2012-05-24
  • 打赏
  • 举报
回复
GC_EXTERNAL_ALLOC freed 与 GC_EXPLICIT freed 是什么?
http://www.cnblogs.com/error404/archive/2011/09/28/2194708.html


09-28 17:16:37.543: DEBUG/dalvikvm(21466): GC_EXTERNAL_ALLOC freed 390 objects / 45656 bytes in 50ms
09-28 17:16:40.513: DEBUG/dalvikvm(3267): GC_EXPLICIT freed 4501 objects / 251624 bytes in 67ms

很多做开发的朋友不明白上面这句是什么意思,给大家解释一下!

前面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。




xqhrs232 2012-05-24
  • 打赏
  • 举报
回复
列几条完整的LOGCAT消息


01-02 00:48:21.750: DEBUG/dalvikvm(2304): GC_EXPLICIT freed 31K, 51% free 2766K/5575K, external 1649K/2078K, paused 27ms

01-02 00:48:36.750: DEBUG/dalvikvm(2304): GC_EXPLICIT freed <1K, 51% free 2766K/5575K, external 1649K/2078K, paused 27ms

01-02 00:48:56.880: DEBUG/dalvikvm(2304): GC_EXPLICIT freed 26K, 51% free 2769K/5575K, external 1649K/2078K, paused 27ms

xqhrs232 2012-05-24
  • 打赏
  • 举报
回复
难道定制的系统存在内存泻漏吗?这样的问题怎么定位啊!我的系统运行时间久了也会越来越慢。头疼的问题又一个!!!
xqhrs232 2012-05-24
  • 打赏
  • 举报
回复
今天试了一下APP跟GPS来回切换,然后再测试系统的可用内存真的是越来越少,怪不得系统跑跑会越来越慢。
总是找到点依据了。

xqhrs232 2012-05-24
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 qthsrs232 的回复:]
What do GC_FOR_MALLOC, GC_EXPLICIT, and other GC_* mean in Android Logcat?
http://stackoverflow.com/questions/4976566/what-do-gc-for-malloc-gc-explicit-and-other-gc-mean-in-android-logcat


C/C++ ……
[/Quote]



Another place where the Dalvik garbage collector messages are explained is in this video: Google I/O 2011: Memory management for Android Apps

At about 14 minutes into the presentation, he breaks down the message format. (BTW, that video has really good info on debugging memory leaks)

Roughly speaking, the format is [Reason] [Amount Freed], [Heap Statistics], [External Memory Statistics], [Pause Time]

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 11719K represents the total heap size. From what I can tell, the heap can grow/shrink, so you will not necessarily have an OutOfMemoryError if 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 and only allocates a few dozen bytes on your local heap). Other examples 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 is mostly done. E.g. paused 3ms+5ms

For non-concurrent GC events, there is only one pause time and it's typically much bigger. E.g. paused 87ms



xqhrs232 2012-05-24
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 qthsrs232 的回复:]
What do GC_FOR_MALLOC, GC_EXPLICIT, and other GC_* mean in Android Logcat?
http://stackoverflow.com/questions/4976566/what-do-gc-for-malloc-gc-explicit-and-other-gc-mean-in-android-logcat


C/C++ ……
[/Quote]



Another place where the Dalvik garbage collector messages are explained is in this video: Google I/O 2011: Memory management for Android Apps

At about 14 minutes into the presentation, he breaks down the message format. (BTW, that video has really good info on debugging memory leaks)

Roughly speaking, the format is [Reason] [Amount Freed], [Heap Statistics], [External Memory Statistics], [Pause Time]

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 11719K represents the total heap size. From what I can tell, the heap can grow/shrink, so you will not necessarily have an OutOfMemoryError if 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 and only allocates a few dozen bytes on your local heap). Other examples 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 is mostly done. E.g. paused 3ms+5ms

For non-concurrent GC events, there is only one pause time and it's typically much bigger. E.g. paused 87ms



qthsrs232 2012-05-24
  • 打赏
  • 举报
回复
What do GC_FOR_MALLOC, GC_EXPLICIT, and other GC_* mean in Android Logcat?
http://stackoverflow.com/questions/4976566/what-do-gc-for-malloc-gc-explicit-and-other-gc-mean-in-android-logcat



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.


qthsrs232 2012-05-24
  • 打赏
  • 举报
回复
What do GC_FOR_MALLOC, GC_EXPLICIT, and other GC_* mean in Android Logcat?
http://stackoverflow.com/questions/4976566/what-do-gc-for-malloc-gc-explicit-and-other-gc-mean-in-android-logcat



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.


qthsrs232 2012-05-24
  • 打赏
  • 举报
回复
What are the “paused” values in GC_CONCURRENT log messages?
http://stackoverflow.com/questions/4525743/what-are-the-paused-values-in-gc-concurrent-log-messages



GC_CONCURRENT Heap is (almost) full. Therefore concurrent GC kicks in

freed 510K - Amount of memory freed

57% free - Memory after freeing %
2529K/5831K - Actual mem in heap
external 716K/1038K - Externally allocated memory (memory that is not in dvm)
paused 8ms+5ms - time taken for GC
especially the "paused" parts

For concurrent collections there are two pause times. One is at the beginning of the collection and other towards the end. For non-concurrent collection there will be only one pause time.


xqhrs232 2012-05-24
  • 打赏
  • 举报
回复

80,472

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧