Frequent Questions      

  Java™ Certification: SCJP™ 6- Sun Certified Java Programmer Exam 


Garbage Collection


           Up           Previous                 Next

Q2. How can you force garbage collection of an object?

A. Garbage collection cannot be forced.
B. Call System.gc().
C. Call System.gc() passing in a reference to the object to be garbage collected.
D. Call Runtime.gc().
E. Set all references to the object to new values(null, for example).

  Correct Answer: A



A is correct. Garbage collection cannot be forced.
B and D are not correct as calling System.gc() or Runtime.gc() is not 100 percent
reliable, since the garbage collection thread might defer to a thread of higher 
C is incorrect as gc method does not take argument.
E makes object to be garbage collected while next time it refers.

   Up           Previous                 Next

Copyright © 2000-2016 All rights reserved

Website design by

Disclaimer: All Simulation Exams practice tests, study guides and/or material are neither sponsored by, nor endorsed by, nor affiliated with Oracle® or any other company. All trademarks are trademarks of their respective owners and duly  acknowledged. OCA™, OCPJP™ are registered trade marks of Oracle® . The practice tests material is a copyright of and the same is not approved or endorsed by respective certifying bodies. Thank-you for your interest in Simulation Exams. Please see read me file before you download, install, and/or use any software from  For any information or questions regarding this Website, please e-mail webmaster at