This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes GC Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "GC" Watch "GC" New topic
Author

GC

lakshmi nair
Ranch Hand

Joined: Oct 11, 2000
Posts: 63
This is a question from anilbachi news letter 19.
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.

I would say b & c are correct.
But the solution is b, c, e.
howz e possible when u cannot guarantee that it runs.
Sudhir Bangera
Ranch Hand

Joined: Oct 10, 2000
Posts: 50
Hi Lakshmi,
I am quoting a sentence from Khalid Mughals book (A Programmers guide to Java Certification) which says " Garbage collector will certainly go to work if there is a danger of running out of memory."
I guess thats why option e is also valid answer.
HTH....
Vaneet Bhutani
Greenhorn

Joined: Sep 13, 2000
Posts: 18
Hold on, I thought that you can not make the Garbage Collector run. You can "suggest" the JVM to put effort towards object recycle via System.gc() & Runtime.gc(). See RHE, pg. 21.
so b is not a correct choice(Let me know if I overlooked something).
Even e is not guaranteed. So, I think the only correct choice is c.
lakshmi nair
Ranch Hand

Joined: Oct 11, 2000
Posts: 63
what i thought by selecting option b is that you can always run (or better call) System.gc(), though it is not for sure that the objects will be garbage collected.
Allan Tan
Greenhorn

Joined: Oct 31, 2000
Posts: 7
I believe 'e' is correct also.
The garbage collector may run at low memory state... or may not, if there's nothing to free up. This doesn't make 'e' false.
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hi guys,
I would say only options c and e are correct.
a) false
You cannot directly free memory allocated by an object.
b) false
There is no guarantee that the garbage collector will run when you call the <code>System.gc()</code> or <code>Runtime.gc()</code> method. The documentation for the <code>gc</code> method states:
"Calling this method suggests that the JVM expends effort towards recycling unused objects."

c) true
The garbage collector calls <code>finalize</code> on an object. The SDK documentation on finalize states:
"Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. A subclass overrides the finalize method to dispose of system resources or to perform other cleanup."

d) false
There is no guarantee that the garbage collector will reclaim the object memory as soon as it becomes garbage collectable.
e) true
If you look at the OutOfMemoryError class description in the SDK documentation, it says:
"Thrown when the Java Virtual Machine cannot allocate an object because it is out of memory, and no more memory could be made available by the garbage collector."

This means that the garbage collector will run in low-memory situations.
Cheers,
Beno�t
[This message has been edited by Beno�t d'Oncieu (edited November 01, 2000).]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: GC
 
Similar Threads
another GC (levteck.com)
Garbage Collection
Booney mock exam q#65
gc
a question about GC