There are plenty of questions on this issue, but no answer satisfied me; I'm coding a simple GUI window using Swing. Currently it only contains 4 buttons and one of them is opening a file chooser.
When I use VisualVM Monitoring tool to look at memory usage, the result is shown below:
memory usage http://img17.imageshack.us/img17/3589/8txc.png
The first pike appeared when I clicked the button, then I did nothing else.
Is this normal for an idle application to consume 10M/min (when it is not doing anything?)
Since I have to do a quizz-like applet with an image, should I use to call System.gc()
each time I switch to the next question to avoid (potentially huge?) memory usage?
Using VisualVM (jvisualvm) jvisualvm is a tool to analyse the runtime behavior of your Java application. It allows you to trace a running Java program and see its the memory and CPU consumption. You can also use it to create a memory heap dump to analyze the objects in the heap.
Set the Heap Size If you reduce the Java heap size by a certain amount you will reduce the memory footprint of the Java process by the same amount. You can however not reduce the Java heap size infinitely. The heap must be at least large enough for all objects that are alive at the same time.
Be mindful of thread use and stack size. The default option -Xss512k means that each thread will use 512kb of memory. The JVM default without this option is 1MB.
Java is consistently listed as using 700MB of real memory.
I could recreate what you saw with a simple test program, but if you let the monitor track a little longer...
CPU was at 0% the whole time (just an open JFileChooser sitting there). The memory fluctuations are curious, but I think the JVM must be doing all kinds of background management and maintenance tasks. That work will use memory which eventually builds up. And periodically it cleans up after itself.
Another thing to consider is that is this memory usage within the already allocated heap. Your program is actually using a consistent amount of real memory the entire time, as you can see from the flat orange line.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With