<Swing Dev> Is the following code supposed to leak?
Clemens Eisserer
linuxhippy at gmail.com
Fri Aug 19 23:42:34 UTC 2011
Hi,
When running the Notepad-Demo shipped with the JDK on caciocavallo-web, I
noticed memory leaks caused by PropertyChangeListeners added to Actions
defined in DefaultEditorKit. Those actions are referenced by a static field
(defaultActions).
I was able to distill the problem down to the following testcase, is the
following code really supposed to leak memory:
while(true) {
final byte[] b = new byte[1000000];
new JTextArea().getActions()[0].addPropertyChangeListener(new
PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent evt) {
b[0] = 0; //Listener will live forever, and so Objects
referenced from here
}
});
}
Thanks, Clemens
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/swing-dev/attachments/20110820/44b782e8/attachment.html>
More information about the swing-dev
mailing list