aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes garbage collection's doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "garbage collection Watch "garbage collection New topic
Author

garbage collection's doubt

Rubel Ahammad
Greenhorn

Joined: Feb 05, 2005
Posts: 19
MindQ's

Which of the following statements about Java's garbage collection are true?

a) The garbage collector can be invoked explicitly using a Runtime object.
b) The finalize method is always called before an object is garbage collected.
c) Any class that includes a finalize method should invoke its superclass' finalize method.
d) Garbage collection behavior is very predictable.

ans given: a,b,c.

But,
a: we only can request garbage collector using Runtime Object.
b: K&B says that , you can't count on the garbage collector to ever delete an object. So Any Code that you put into your class's overriden finalize() method is not guaranteed to run.

I think only correct answer is c.
coz:
Kalid Mugal's SCJP1.2 Says(Page 253) "Finalizers are not implicitly chained like constructors for subclasses, therefore a finalizer in a subclass should explicitly call the finalizer in its superclass as its last action.


rubel ahammad<br /> <br />SCJP 1.4 (91%)<br />SCWCD 1.4 (Preparing)
Arvind Giri
Ranch Hand

Joined: Jun 26, 2005
Posts: 91
.
Dear Rubel,
The 2nd option can be taken in other words as "before an object is garbage collected, the finalize method is always called". now it seems ok.

and about 1st option he is saying only abt invoking. which doesn't mean sure excution. explicitly invoking is like making request.


Regards<br /> <br />Arvind Giri<br />MCA,SCJP 1.4,SCWCD 1.4<br />Looking for SCDJWS
Surasak Leenapongpanit
Ranch Hand

Joined: May 10, 2002
Posts: 341
Option a) can be called by System.gc() or Runtime.gc().
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: garbage collection's doubt