问题
I'm currently doing a research invovling a bit of the JVM and how it's memory usage works. What I don't understand is, what does the JVM fill it's memory with when idle, just to release it all when the heap is almost reached? Why isn't there just one flat line of used memory? btw, this java application is hosted on glassfish, but I have the same graphs when I just have an easy 'hello world' swing application. So GlassFish doesn't have to do anything with it.

Thanks in advance!
回答1:
what does the JVM fill it's memory with when idle, just to release it all when the heap is almost reached?
If your application is genuinely idle, the most likely case is VisualVM. Try reducing the sample rate and see if the rate memory is consumed also drops.
Why isn't there just one flat line of used memory?
JMX is written in Java so when it collects stats and serialises the data it generates quite a bit of garbage. You can turn on memory profiling to confirm that all the memory consmption is JMX & VisualVM related. If you use a commercial profiler which uses a native agent to monitor the JVM you don't see this behaviour. e.g. YourKit doesn't do this.
来源:https://stackoverflow.com/questions/13123457/jvm-sawtooth-idle-process