I have this simple Java Code which creates a single JFrame instance and displays it. This link contains the screenshot of memory consumption graph taken by jconsole

What worries me is that java.exe in task manager shows memory usage continuously increasing at the rate of 4-5 kbs every 8-9 seconds. Need help
import javax.swing.*;
class MyGUI extends JFrame
{
public void makeGUI()
{
setLayout(null);
setSize(500, 200);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
}
public class Launcher
{
public static void main(String []args)
{
SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
new MyGUI().makeGUI();
}
});
}
}
The profile looks perfectly normal - the program creates objects and from time to time, the garbage collector frees memory by getting rid of the objects that are not reachable any longer.
The important observation is that the trough points are all more or less at the same level so it does not look like your code has a memory management issue.
You could reduce the height of the peaks by setting the maximum amount of heap space to a lower level but 5 MB is not much anyway...
I think that this memory is due to the generation of the objects used by swing, like the various UI events (mouse movement, etc...). Swing tends to generate objects for every events and call the listeners handling those events. After that these event-related objects are not used anymore (except if you keep reference to them).
This is not a memory leak, it's normal behaviour. In fact, in your screenshot of the memory consumption, the memory fall sharply when the garbage collector free these objects.
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