0

I was creating a simple JFrame window and check the windows task manager for memory usage and when I tried to resize the JFrame using the mouse pointer not the maximum button it add a lot of memory from 51,000k to 400,000k and it never goes down but when I used the maximum button it didnt even adds memory.

What is causing it to add a lot of memory and it never goes down?

Image bg = new ImageIcon(getClass().getResource("circle.png")).getImage();
    JFrame jf = new JFrame("MySqlConnections");
    jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    jf.setSize(400,400);
    jf.setIconImage(bg);
    new ConnectMysql(jf);
    jf.setLocationRelativeTo(null);
    jf.setPreferredSize(new Dimension(xFrame, yFrame)); 
    jf.setMinimumSize(jf.getPreferredSize());
    jf.setVisible(true);


public static void main(String[] args) {
    new MainFrame();
     /* Total number of processors or cores available to the JVM */
    System.out.println("Available processors (cores): " + 
        Runtime.getRuntime().availableProcessors());

    /* Total amount of free memory available to the JVM */
    System.out.println("Free memory (bytes): " + 
        Runtime.getRuntime().freeMemory());

    /* This will return Long.MAX_VALUE if there is no preset limit */
    long maxMemory = Runtime.getRuntime().maxMemory();
    /* Maximum amount of memory the JVM will attempt to use */
    System.out.println("Maximum memory (bytes): " + 
        (maxMemory == Long.MAX_VALUE ? "no limit" : maxMemory));

    /* Total memory currently in use by the JVM */
    System.out.println("Total memory (bytes): " + 
        Runtime.getRuntime().totalMemory());

    /* Get a list of all filesystem roots on this system */
    File[] roots = File.listRoots();

    /* For each filesystem root, print some info */
    for (File root : roots) {
      System.out.println("File system root: " + root.getAbsolutePath());
      System.out.println("Total space (bytes): " + root.getTotalSpace());
      System.out.println("Free space (bytes): " + root.getFreeSpace());
      System.out.println("Usable space (bytes): " + root.getUsableSpace());
    }

}
Dasda Sdasd
  • 73
  • 1
  • 9

1 Answers1

2

It may add memory as you are resizing step by step, it needs to repaint the full frame again and again. Why it doesn't go down because it depends on garbage collector which doesn't run immediately whenever there's scope to free some memory.

vishal_aim
  • 7,636
  • 1
  • 20
  • 23