Hello i am programming twin panel file manager in java and i am facing a problem.
Whenever I scroll JTable
it takes about 8M more memory... Is there a way how to fix that ? It stops everytime after consuming 40 - 60M of memory. Is it a Swing
component problem ?
Thank you for your responses.
Edit
I tried to understand why it takes so much memory. Now i know the source of the problem. I made a small button with this actionPerformed:
jScrollPane1.repaint();
.
When I hit it 10 times i got big memory consumptions in task manager and also in VisualVM. But in VisualVM GC starts to collect on 50 MB and lowers it to 8 Mb. But windows taskmanager is still increasing its value.
The repaint method is making big memory leaks in windows. Is there any fix ?
Edit2
A further research of this problem gave me this. I tried to run this program on Linux platform with no leaking. The program had about 20 M of memory used. So i've programmed a little thread which was invoking the method repaint on both JScrollPanes
. And to my suprise on Windows machine memory was rising until 110 M but then the OS started to push harder on memory.
The Thread:
@Override
public void run() {
while (true) {
jScrollPane1.repaint();
jScrollPane2.repaint();
try {
this.sleep(10);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
}
}
I was doing normal copy/rename/delete operations also was going through directories with no memory rising. I noticed that the memory was also decreasing to 99M.
On the monitoring thread:
@Override
public void run() {
while (true) {
aLabel.setText("Memory consumption: " + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory());
try {
this.sleep(200);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
}
}
the numbers were from 8M to 50M and then again 8M. So garbage collecting was successful. So the real problem is windows platform or the compatibilty of the JVM ? As trashgod suggested that task manager is not precise in getting the memory consumptions but the memory is being really used by the java process.