Sim-Ex™ Practice Exams for Java SE 8 Programmer II: Sample Questions

Garbage Collection

Home     Previous     Up     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.

Home     Previous     Up     Next

Disclaimer: is not affiliated with any certification vendor, and Sim-Ex™ Practice Exams are written independently by and not affiliated or authorized by respective certification providers. Sim-Ex™ is a trade mark of or entity representing® is a trademark of Oracle™.