aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Is this right? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Is this right?" Watch "Is this right?" New topic
Author

Is this right?

yun lou
Greenhorn

Joined: Jul 13, 2002
Posts: 5
The garbage collector informs your object when it is about to be garbage collected
right or wrong?
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
right, by invoking ONCE the finalize method of your object.
From the Object API:

protected void finalize()
Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.


SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
yun lou
Greenhorn

Joined: Jul 13, 2002
Posts: 5
Thank you! You are a really cool man! I will take the exam 16 Aug.
Younes Essouabni
Ranch Hand

Joined: Jan 13, 2002
Posts: 479
good luck for the exam!


Younes
By constantly trying one ends up succeeding. Thus: the more one fails the more one has a chance to succeed.
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
Good luck Yun
Barkat Mardhani
Ranch Hand

Joined: Aug 05, 2002
Posts: 787
Hi Val:
Quote from your note above:
right, by invoking ONCE the finalize method of your object.
From the Object API:

I think in first GC run, finalize will be
invoked and second GC run the object will be
cleared. Right?
Thanks
Barkat
Soum Sark
Ranch Hand

Joined: May 31, 2002
Posts: 50
According to the mark & sweep algorithm the first time it marks objects and then the second time it sweeps .. so any unmarked objects would be collected the second time ..pls correct me if i am mistaken
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
Neither the JLS nor the JVMS require the use of the mark & sweep algorithm for garbage collection. In fact, the choice of the algorithm is completely up to the JVM vendor. Thus, such assumptions cannot be made.
Ron Newman
Ranch Hand

Joined: Jun 06, 2002
Posts: 1056
If your finalize() method "resurrects" the object by making it reachable again, then the next time it becomes unreachable, the garbage collector will not call finalize() a second time.


Ron Newman - SCJP 1.2 (100%, 7 August 2002)
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Is this right?