esuslogo
 [To advertise Java(tm) Events here, contact joris@esus.com!]
banner

Java™
by example!






New @ Esus.com


  gb  In-house search engine for better results!

  gb  Get updates with the esus.com
newsletter!









  Home 
 Browse Categories 
 Ask a Java Question 
 Help 
  For Java Tips & Tricks, subscribe to the esus.com newsletter!
Search Java Q&A, Links, API's:   adv 

How do I create a destructor in Java?
In C++, a destructor typically cleans up resources (dynamically allocated memory, open file handlers, ...). In Java, the garbage collector automatically frees up a dynamically created object whenever there are no more references pointing to that object. Sometimes, it may occur that you want to free up extra resources. You could then implement the protected void finalize() method which will be executed when the garbage collector decides to free up the object. However, this method implies the behavior of your program is totally dependent on the garbage collector. A more reliable way is to use the try / catch / finally block to clean up extra resources because you can be certain that the finally block will be executed regardless of any exceptions thrown.


Further Information
Author of answer: Joris Van den Bogaert

Comments to this answer are only viewable by members. Login or become a member!





Terms of Service | Privacy Policy | Contact

Copyright © 2000-2003 Esus.com - All Rights Reserved 
Java and all Java-based trademarks are trademarks of Sun Microsystems, Inc. Esus.com is independent of Sun Microsystems, Inc. All other trademarks are the sole property of their respective owners.