aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes explicit finalize( )? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "explicit finalize( )?" Watch "explicit finalize( )?" New topic
Author

explicit finalize( )?

Sandra Baker
Greenhorn

Joined: Jul 10, 2002
Posts: 26
Hi, is it necessary to explicitly implement finalize() method in every class we defined? I thought it would be taken care of by JVM.... thanks
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Hi Sandra,

Hi, is it necessary to explicitly implement finalize() method in every class we defined? I thought it would be taken care of by JVM....

Nope. The only time you need finalize is for any clean up that might be required when the GC scoops up the object. For example closing a file or database connection.
Hope this helps,
Michael Morris


Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17260
    
    6

And to be totally honest, you should avoid using a finalize method at all costs. You have no guarantee of when the finalize method will be called. And having a finalize method allows for what is called reincarnating a dead object. Which leads to other problems.
Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: explicit finalize( )?