Skip to main content

Issues with JFrame increasing in memory

4 replies [Last post]
jarodwpeters
Offline
Joined: 2007-07-12
Points: 0

I wrote a simple java 'notepad' program. I did it so I could customize it for what I do at work and to be able to keep track of different notes. I found today that the memory just increases on it. So I decided to take away almost all of the code. It is now only creating a JFrame. It still appears to grow in memory usage - just not as fast. Below is my code:

import javax.swing.JFrame;
import javax.swing.SwingUtilities;

public class Ui{

//Declaring Swing Components
private JFrame jFrame = null;
//Declare constants
final String C_NAME = ("Notes");

//Launching application
public static void main(String[] args){
SwingUtilities.invokeLater(new Runnable() {
public void run() {
Ui application = new Ui();
application.getJFrame().setVisible(true);
}
});
}

//Create the Frame and define default behaviors
JFrame getJFrame() {
if (jFrame == null) {
jFrame = new JFrame();
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jFrame.setSize(800, 600);
jFrame.setTitle(C_NAME);
}
return jFrame;
}
}

This would increase in memory and not clean up. Sometimes it would clean up memory if I minimized the window. If you compile this just start clicking on the frame and watch the memory usage increase.

I went ahead and used hprof:

>java -agentlib:hprof=heap=sites -jar MemoryLeak.jar

Here is the output from that:
SITES BEGIN (ordered by live bytes) Mon Oct 13 19:27:59 2008
percent live alloc'ed stack class
rank self accum bytes objs bytes objs trace name
1 60.08% 60.08% 1768720 1 1768720 1 303823 int[]
2 1.39% 61.47% 40816 27 40816 27 303589 sun.java2d.loops.GraphicsPrimitive[]
3 1.37% 62.84% 40360 347 40648 349 300142 char[]
4 0.56% 63.39% 16416 2 16416 2 300063 byte[]
5 0.56% 63.95% 16400 1 16400 1 303206 char[]
6 0.50% 64.45% 14672 262 14728 263 301734 java.awt.event.InvocationEvent
7 0.46% 64.91% 13680 190 13680 190 303762 java.awt.event.MouseEvent
8 0.42% 65.33% 12312 513 12312 513 301757 java.lang.ref.WeakReference
9 0.38% 65.71% 11208 467 11232 468 301746 java.awt.EventQueueItem
10 0.36% 66.08% 10704 446 10704 446 302741 java.util.Hashtable$Entry

I am compiling using java 1.6.0_05 and also that is what my machine is running. Let me know if anyone has any ideas.

Thanks

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
jarodwpeters
Offline
Joined: 2007-07-12
Points: 0

Previous resolution was not correct

jarodwpeters
Offline
Joined: 2007-07-12
Points: 0

NM I found a bug that hasn't been corrected yet.

Bug ID: 6462383

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6462383

linuxhippy
Offline
Joined: 2004-01-07
Points: 0

as far as I can see the bug yuo mentioned was already fixed in jdk6u1, so its most likely not the cause...

lg Clemens

jarodwpeters
Offline
Joined: 2007-07-12
Points: 0

Can you look at the code I provided above and let me know what you think. There isn't much there except creating my jFrame but I am still able to make it grow in memory without putting any of my other code in.