0
我正在創建一個簡單的JFrame窗口並檢查Windows任務管理器的內存使用情況,並且當我嘗試使用鼠標指針調整JFrame大小而不是最大化按鈕時,它會從51,000增加大量內存k到400,000k,它永遠不會下降,但當我使用最大的按鈕,它甚至沒有增加內存。調整JFrame的大小添加大量內存
是什麼導致它增加大量的內存,它永遠不會停機?
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());
}
}
這將有很多與你在做什麼,當框架調整大小。你能否提供演示問題的示例代碼... – MadProgrammer 2013-05-12 07:24:59
爲了更快提供更好的幫助,請發佈[SSCCE](http://sscce.org/)。已編輯 – 2013-05-12 07:36:59
。 – 2013-05-12 07:53:55