• Post Reply Bookmark Topic Watch Topic
  • New Topic

explicit finalize( )?  RSS feed

 
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
 
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
 
ranger
Sheriff
Posts: 17314
11
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
Boost this thread!