Using Java Swing Memory

There are many questions on this, but no answer has satisfied me; I am coding a simple GUI window using Swing. Currently, it contains only 4 buttons, and one of them opens a selection file.

When I use the VisualVM monitoring tool to view memory usage, the result is shown below:

memory usage http://img17.imageshack.us/img17/3589/8txc.png

The first pike appeared when I pressed the button, and then did nothing.

Is it normal for a standby application to consume 10 M / min (when it does nothing?)

Since I have to make an applet with image widgets, should I use System.gc() to call every time I switch to the next question to avoid using (potentially huge?) Memory?

+6
source share
2 answers

I could recreate what you saw with a simple test program, but if you let me monitor the monitor a little longer ...

enter image description here

The CPU was always at 0% (only open JFileChooser was sitting there). Memory swings are curious, but I think the JVM should do all kinds of background management and maintenance. This work will use memory, which will eventually grow. And periodically he cleanses after himself.

Another thing to consider is memory usage in an already allocated heap. Your program actually uses a constant amount of real memory all the time, as you can see from the flat orange line.

+2
source

I think the problem is in JFileChooser. When I used it, I noticed that fileChooser is "waiting for something." And when I closed the program incorrectly, fileChooser throws an error. Maybe this will help you :)

0
source

All Articles