• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Finalize method

 
Raveendran Hs
Greenhorn
Posts: 23
Eclipse IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it possible to skip the execution of finalize method for a given object.
 
Jim Hoglund
Ranch Hand
Posts: 525
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, it will always run. But you can include code in finalize that will recognize
the situation you are concerned about and take appropriate action.

Jim ... ...
 
Rob Spoor
Sheriff
Pie
Posts: 20610
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jim Hoglund wrote:No, it will always run.

Not necessarily. The JVM may exit before finalize() will be called. The only thing that can be said about finalize() is that it is called at most once for each instance and if it will be invoked this will occur before the object is garbage collected.

But programmers have no control over when it will or will not be called.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic