Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

explicit finalize( )?

 
Sandra Baker
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic