GeeCON Prague 2014*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Reg. GC 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 "Reg. GC " Watch "Reg. GC " New topic
Author

Reg. GC

Angela Narain
Ranch Hand

Joined: Apr 14, 2001
Posts: 327
Following is a question from Barry Boone's exam :
Which statements about garbage collection are true?
Select all valid answers.

a.You can directly free the memory allocated by an object.
b.You can directly run the garbage collector whenever you want to.
c.The garbage collector informs your object when it is about to be garbage collected.
d.The garbage collector reclaims an object´┐Żs memory as soon as it becomes a candidate for garbage collection.
e.The garbage collector runs in low-memory situations

The correct answer is b,c,e.
But i am not clear about the statement c.
Can someone explain it to me.
james hoskins
Ranch Hand

Joined: Jun 28, 2001
Posts: 31
hello angela,
gc informs an object of its imminent demize by calling is finalize() method.
kind regards,
james hoskins
Angela Narain
Ranch Hand

Joined: Apr 14, 2001
Posts: 327
Is there some internal mechanism by which it informs the object
that it is going to be gced.

Muhammad Farooq
Ranch Hand

Joined: May 08, 2001
Posts: 356
How come b is correct?
--Farooq


Muhammad Farooq<br />Sun Certified Programmer for Java 2 Platform<br />Oracle8i Certified Professional Database Administrator
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
I agree with you Muhammad, I think we are faced with a poorly worded answer again... b would be correct if the answer would be "You can directly INVOKE the garbage collector whenever you want to."
Though no warranty is given whether the gc will be run directly or not !
Val


SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
Muhammad Farooq
Ranch Hand

Joined: May 08, 2001
Posts: 356
Thanks Val, but ur response creates a confusion in my mind, when we say invoke, doesn't it mean run. I think all we can do is to try to run or try to invoke, all we can't do is to force to do it.
--Farooq
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
Invoke means actually call a method upon an instance of an object, like this
String s = "String1";
s.trim();
here you invoke the method trim upon instance s.
Concerning the gc, you invoke gc() upon the class System. What System.gc() does is invoking gc() on an instance of class Runtime (Runtime.getRuntime().gc()). Note that the method gc in class Runtime is native. It is up to the method gc() to actually try to make the garbage collector run, but nothing is guaranteed. It is not because you "invoke" a method that the body of that method will be sequentially executed.
Another example is the method start() of the class Thread. When you "invoke" the method start() on an instance of a Thread, the method returns almost immediately even if the Thread instance is not started yet.
All this to say that "invoking" the method gc() does not mean "running" the garbage collector, but just that "you'd like the garbage collector to run now".
let me know Muhammad if you are still confused !
Val
Muhammad Farooq
Ranch Hand

Joined: May 08, 2001
Posts: 356
Thanks a lot Val.
--Farooq.
Angela Narain
Ranch Hand

Joined: Apr 14, 2001
Posts: 327
Consider the below two statements :

1. You can call the garbage collector whenever you want to. (True/False )
2. You can directly run the garbage collector whenever you want to.
(True/False)

According to me :
1. This statement is more like the statement "Garbage collection can be forced" which should be false.
2. Is this statement similar to what we mean by making a call
System.gc() ? But then it should have been donot have been "invoke"
instead of "run"
Pls. explain..I am still not clear .

Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
1. you can call gc means you can invoke gc which is true
2. you can run means than if you invoke the gc then it will immediately run, which is false
Val
 
 
subject: Reg. GC