Meaningless Drivel is fun!*
The moose likes Java in General and the fly likes Finalize method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Finalize method" Watch "Finalize method" New topic
Author

Finalize method

Hs Raveendran
Greenhorn

Joined: Feb 05, 2010
Posts: 23

Is it possible to skip the execution of finalize method for a given object.
Jim Hoglund
Ranch Hand

Joined: Jan 09, 2008
Posts: 525
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 ... ...


BEE MBA PMP SCJP-6
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19679
    
  18

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Finalize method