• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Garbage Collection

 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which statements were true about GC?
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 your object's memory as soon as it becomes a candidate for garbage collection.
e. The garbage collector runs in low memory situations.
f. GC mechanism strictly defined in the JVM.
Please someone tell me the correct answers?
 
Paul A
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
a. You can directly free the memory allocated by an object.
False. Memory can only be freed by the GC. (It's the boss out there!)
b. You can directly run the garbage collector whenever you want to.
False. You can only request. (by calling System.gc() etc.) When it actually runs depends (on its mood??) ...on it's implementation.
c. The garbage collector informs your object when it is about to be garbage collected.
True. by calling finalize() on that object.
d. The garbage collector reclaims your object's memory as soon as it becomes a candidate for garbage collection.
False. It reclaims the memory when it runs and not when the object becomes available for gc.
e. The garbage collector runs in low memory situations.
False. Not Neccessory. Somebody may write a JVM that runs the GC every 10 mins! It's not specified by Sun.
f. GC mechanism strictly defined in the JVM.
All it says is that the object's finalize() will be called just before it is GCed. Now, I don't know whether it is strictly defined or not. I would guess, No.
HTH,
Paul.
------------------
http://pages.about.com/jqplus
Get Certified, Guaranteed!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic