aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes From Boone's  Exam Again 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 "From Boone Watch "From Boone New topic
Author

From Boone's Exam Again

swati bannore
Ranch Hand

Joined: Oct 18, 2000
Posts: 201
Question 65: 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.
Answer Given - b,c,e
I think,B is again not correctly worded...or is it..I hope,in real exam , wordings are more clear..
Comments--
Thanx

Swati Kale
SCJP
SCWCD
Dian He
Greenhorn

Joined: Aug 03, 2001
Posts: 12

my understanding b is not right.
you can call garbage collector whenever you like, but it can not be sure when it will actually run.
Vedhas Pitkar
Ranch Hand

Joined: Jan 27, 2001
Posts: 445
Hi,
I think that only e is correct as u can't be sure whether the garbage collection will take place or not.
Bindesh Vijayan
Ranch Hand

Joined: Aug 21, 2001
Posts: 104
Hi,
I think one can forcefully run the garbage collector by calling System.gc() method.In this way you force garbage collector to be called to reclaim the memory.If a forceful call is not done then the gc is called only when the JVM finds it is running low in memory,otherwise it will not call garbage collector and the memory will be reclaimed by the Operating System when the program ends.Although calling garbage collector is a waste of time.So I think b and e both are right and since I have no idea of any information being given to object by the gc, I'll stay quite.
If you want to see an example where you call gc and see the process of gc,then here is the code:-

One thing that I must add to the behavior of the program is that Iam not assigning it to any variable of A (see line#1) ,thus the objects created using new remains unreferenced thereby creating work for garbage collector.Had it been assigned to any object reference gc would'nt have work.I found it out lately.
This is what my understanding says,I may be wrong, so please correct me.
THANKS
[This message has been edited by Bindesh Vijayan (edited August 29, 2001).]
Jennifer Warren
Ranch Hand

Joined: Aug 24, 2001
Posts: 53
my understanding is that gc is a thread and one can not be sure when it is going to run even after the System.gc(); method.
correct me if i'm wrong.
thanx.
Jennifer
swati bannore
Ranch Hand

Joined: Oct 18, 2000
Posts: 201
Hi,
I think ,c and e, are correct options.
Regarding b,Yes, we can call System.gc() but we can NOT guarantee that Garbage Collector will run..So the option.."You can run directlt Garbage Collector" Whenever you can" shd be false.
Regarding C, Objects gets notified before actual Garbage Collection...remember finalize() is called..
Hope it is correct...
Thanx
 
 
subject: From Boone's Exam Again