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
posted
0
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
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