This week's book giveaway is in the JavaFX forum.
We're giving away four copies of Introducing JavaFX 8 Programming and have Herbert Schildt on-line!
See this thread for details.
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 Introducing JavaFX 8 Programming this week in the JavaFX forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Finalize method" Watch "Finalize method" New topic
Author

Finalize method

Raveendran Hs
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: 20128
    
  30

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 - OCEJPAD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Finalize method
 
It's not a secret anymore!