aspose file tools*
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

Bubai Basu
Greenhorn

Joined: May 23, 2007
Posts: 4
1.Objects that have finalize() methods always have their finalize() methods called before the program ends??
2.Objects that have finalize() methods are ever garbage collected ??
Please give me some document on Finalize method.
Maurizio Nagni
Ranch Hand

Joined: May 29, 2004
Posts: 75
1) when you write a finalize method in your class you are overriding the finalize method (that i suppose to be empty) of the Object class. In this way when the garbage collector destroy the object it is instructed with the "last will" of your class

2) first of all an object is garbageColected when the Garbage collector choose that the time has come, but also one those two conditions have to true:
a) the object has been set to null (obj = null
b) finalize method of the object has been called;

ciao
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

1) No, there is no guarantee that finalize() will be called on all objects; only that an object's finalize() will be called when it is collected and its memory is reclaimed.

2) Having a finalize() method has no effect on whether or not an object will be garbage collected (unless finalize() does something ugly, like storing a reference to the object somewhere.)


[Jess in Action][AskingGoodQuestions]
Mike Mc Afee
Greenhorn

Joined: Jan 31, 2007
Posts: 19
Here is what Sun has to say about it Java 2 Platform SE 5.0 API
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Finalize Method