15

我的目录中有以下消息,

GC_CONCURRENT freed 456K, 19% free 2753K/3360K, paused 5ms+9ms, total 378ms

我试图弄清最后一个总值。我在网站上检查了其他与 GC 相关的问题,它们要么有两个与并发 GC 相关的暂停,要么有一个非并发 GC 的总暂停。为什么我有两个?我的应用暂停了 5+9 毫秒还是 378 毫秒?究竟什么是总数?

4

5 回答 5

6

没有明确的答案,但据我所知,GC_CONCURRENT 是一个在单独线程中运行的垃圾收集。这意味着虽然运行总共可能需要 X 毫秒(在您的情况下为 378),但您实际运行的线程不会被阻塞那么长时间。它只会在并发垃圾收集过程的开始和结束时被阻塞一点(在您的示例中为 5+9=14ms)

这种类型的垃圾收集由 JVM 自动触发,当它决定是这样做的好时机时(通常是当堆变得危险地高时)。其他类型的 GC,例如 GC_EXPLICIT(如果我没记错名字的话)会在您执行

System.gc();

在你的代码中。对于这种类型的垃圾收集,它只会报告一次(如 Y ms),在这种情况下,您的线程实际上将被阻塞一段时间,直到这种类型的 GC 进程完成。

于 2013-04-03T11:20:30.320 回答
6

GC_CONCURRENT: Triggered when the heap is growing. So it can reclaim memory in time so the heap doesn't need to be enlarged

GC_CONCURRENT freed 456K

This part tells you how much memory was freed by this GC sweep

GC_CONCURRENT freed 456K, 19% free 2753K/3360K

This part tells how much % of the heap is free, the size of the alive objects and the total size of the heap. So in the above example the 19% free, there is 2753Kmemory in use and the total heap size is 3360K.

The last part of the log tells you how long the GC took. on a GC_CONCURRENT collection you will see 2 times. one at the beginning of the collection, and one at the end.

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

Source:

https://sites.google.com/site/pyximanew/blog/androidunderstandingddmslogcatmemoryoutputmessages

Another place where things are explained clearly...

http://www.youtube.com/watch?v=_CruQY55HOk

于 2013-04-03T11:15:12.610 回答
2

从我查看的一些 systraces 看来,总数(378 毫秒)并不能反映 GC 实际暂停您的应用程序的时间。它确实反映了垃圾收集花费了多长时间。暂停时间是您应该关注的。

于 2015-02-10T01:12:06.350 回答
1

Take a look at this question it explains the garbage collection messages etc.
If you need more information watch this video from google about memory management

于 2013-04-03T11:14:17.460 回答
0

http://www.youtube.com/watch?v=_CruQY55HOk.

Watch the video around 17 minutes. The guy explains the logcat message in detail.

GC_CONCURRENT freed 456K, 19% free 2753K/3360K, paused 5ms+9ms, total 378ms
GC_CONCURRENT : Jumps in because Heap is growing
19% free 2753K/3360K After this collection 19% of memory is free. Check the heap usage.paused 5ms+9ms Time taken to collect garbage. Total pause time is 378ms.
于 2013-04-03T11:14:24.033 回答