Why does idle Java application generate 20 MB garbage in 4 minutes?

I was testing performance of Guava cache by loading 5000 objects in cache using 50 threads using ExecutorService. I wanted to see the heap occupied by the cached objects.

It looked as though the cached objects were eating up 25MB.

Later, I put a Thread.sleep on the main thread to sleep the application for 10 minutes, so that I could sample the memory etc.

Surprisingly, even when the application is on sleep, it generates 20MB of garbage every 4 minutes. Since there is a GC operation every 4 minutes, I am seeing a Sawtooth wave in the used heap graph. 在这里输入图像描述

Why does java generate 5MB of garbage per minute in an idle application?

UPDATE : I ran just a main method with only a call to Thread.sleep for 10 minutes.

Memory allocation is 4 MB per minute. 在这里输入图像描述

Below is the memory sampler screenshot. Looks like only the RMI TCP connection thread which is causing all the activity. 在这里输入图像描述

Is it just the fact that we are observing with VisualVM causing all that activity? Or is it regular jvm activity?


As the bottom line: no one can answer such question without profiling your application. What you need is to take a memory snapshot in visual VM and check what classes are taking large amount of memory. Also it helps to sort the object counts and see which objects have most instance count change before and after the GC.

For a quick glimipse, since you have 11 threads shown in your pic, at least you have the node objects for the Runnable objects submitted to your ExecutorService , which most of the current Java libs and packges would opt.


You were using VisualVM to monitor your application. VisualVM is using JMX/MBeans to get monitoring information. JMX is using RMI as transport layer. VisualVM is polling MBeans regularly which translates to calling service running on your JVM via RMI.

4 MiB per minute sounds to be reasonable number to blame VisualVM for.

I suggest you to monitor you process with SJK ttop command. It displays memory allocation rate per thread, so you can verify if all garbage could be attributed to RMI threads or any of your application thread do some littering.

链接地址: http://www.djcxy.com/p/79962.html

上一篇: 在VisualVM中禁用执行GC和CPU监视

下一篇: 为什么空闲Java应用程序在4分钟内生成20 MB垃圾?