Re: REAL SSCCE of my graphical interface with memory leaks
I ran 'your'* code for 8 hours on Win XP Pro using
Java 1.6.0_02**. Besides that, I also ran jconsole
(part of the 1.6 SDK, not sure of earlier versions).
Here is screenshots of the results.
* You code was horrible. Besides the wrapped long line
that broke compilation, and the fact the main could be
included within the one public class, there were a number
of other things about the code I simply 'could not abide'.
I changed those aspects of the code, but I believe the version
I used was substantively the same as yours, and will
*demonstrate the same behaviour on your testing PC.*
The code I used is linked from the page.
*Please run it and confirm the same behaviour you
reported as a 'memory leak'.*
OTOH, given you obviously put a lot of effort into that
example, and barring the single broken line, it was an
SSCCE (or a close facsimile thereof***), so I thought it
deserved a little more attenetion.
** Yes yes, I know.. _03 is the only safe version,
I am evil for using _02 blah-de-blah..
*** Given it failed to satisfy the 'E' in that it was
not an example of a memory leak.
I agree with pretty much every comment made by
each person who has replied to this thread. I think
you are failing to understand the nature of Java GC
(and just how 'lazy' it can be).
There is no 'memory leak' in the code shown.
I am just hoping these screenshots can convince you
that your fears are unfounded.
OTOH, if your app. actually hits OutOfMemoryErrors,
we need to look more closely at what it is doing, and
(if my addled memory serves me well) what is happening
with any Image's and ImageIcon's..
public class Interfaccia2 extends JFrame
/** Used to update the timeField label. */
/** Original Timer was set for a 1000 ms delay.
The delay used here, in ms, is.. */
int delay = 10;
final JLabel timeField = new JLabel("");
timer = new Timer(
public void actionPerformed(ActionEvent e)
Calendar now = Calendar.getInstance();
int day = now.get(Calendar.DAY_OF_MONTH);
int mese = now.get(Calendar.MONTH)+1;
int anno = now.get(Calendar.YEAR);
int h = now.get(Calendar.HOUR_OF_DAY);
int m = now.get(Calendar.MINUTE);
int s = now.get(Calendar.SECOND);
"Data: " + day +
"-" + mese +
"-" + anno +
" Ore: " + h +
":" + m +
":" + s);
JPanel panelPrincipale = new JPanel();
/** Start the timer */
public void start()
public static void main(String args)
Runnable r = new Runnable()
public void run()
Interfaccia2 app = new Interfaccia2();
Message posted via JavaKB.com