This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

garbage collection

 
mrudul joshi
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
Thanks
Mrudul
 
Sagarika nair
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic