How can you force garbage collection of an object in Java?

  1. Garbage collection cannot be forced

  2. Call System.gc()

  3. Call System.gc(), passing in a reference to the object to be garbage-collected

  4. Call Runtime.gc()

  5. Set all references to the object to new values (null, for example)


Correct Option: A

Find more quizzes: