File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes garbage collection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

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

garbage collection

mrudul joshi
Ranch Hand

Joined: Nov 12, 2003
Posts: 54
11. Which statements about garbage collection are true?
A) The garbage collector runs in low memory situations
B) You can run the garbage collector when ever you want.
C) When it runs, it releases the memory allocated by an object.
D) Garbage collector immediately runs when you set the references to null.
The answers given are A and C, but I think we cannot predict when the garbage collector runs, so the answer should be only C.
Please clarify.
Sagarika nair
Ranch Hand

Joined: Aug 13, 2003
Posts: 39
The K & B book states that the behavior when gc() is called may be different for different JVMs,so there is no guarantee that the unused objects will be removed from memory.
About the only thing you can guarantee is that if your program is running very low on memory , the garbage collector will run before it throws an OutOfMemoryException.
I hope that helps.
I agree. Here's the link:
subject: garbage collection
It's not a secret anymore!