dispose : Java Glossary
home D words local find no local find frame, full screen Google search web for topic jump to footer translate with Babelfish by Roedy Green ©1996-2008 Canadian Mind Products
Go to : punctuation 0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z (all)
dispose
Free up and recycle any behind-the-scenes peer resources this component is using (e.g. inside the native GUI).

You most commonly use dispose in a windowClosing event handler for a JFrame or Frame.

Java can automatically garbage collect stranded objects created by Java, but it needs this help arranging to recycle resources inside the brain-damaged native GUI. This does not delete the current Container itself. E.g. dispose for a Panel would remove the panel from the screen, and would discard all the paraphernalia needed to put the panel on the screen, but all the panel fields would still be intact.

It is wise to arrange to dispose of any unneeded Graphics objects you obtained with getGraphics.

If you just hide frames rather than disposing of them, they can be made visible again more quickly. On the other hand, if you are truly finished with a frame, the associated GUI peer resources the invisible frame is holding onto won’t be recycled. Rule of thumb, use dispose, and only if you need to fine tune, sometimes use setVisible( false ) instead for free standing Frames, JFrames and Windows. use setVisible( false ) for everything else.

dispose cannot be counted on to do built-in setVisible( false ). Do your own setVisible( false ) first. I have not experimented, but I doubt that dispose removes children. When disposing Frames, you must disconnect any off-frame Listeners and any references to the Frame, if you want the Frame itself to be garbage collected.

Image.flush() should really be called Image.dispose().


CMP_homejump to top
CMP logo
feedback Please email your feedback for publication, errors, omissions, broken/redirected link reports
and suggestions to improve this page to Roedy Green : feedback email
made with CSS
HTML Checked!
ICRA ratings logo
mindprod.com IP:[65.110.21.43]
Your face IP:[38.103.63.18] The information on this page is for non-military use only.
You are visitor number 24,505. Military use includes use by defence contractors.
You can get a fresh copy of this page from: or possibly from your local J: drive (Java virtual drive/Mindprod website mirror)
http://mindprod.com/jgloss/dispose.html J:\mindprod\jgloss\dispose.html