Java OCA OCP Practice Question 257

Question

How do you force garbage collection to occur at a certain point?

  • A. Call System.forceGc()
  • B. Call System.gc()
  • C. Call System.requireGc()
  • D. None of the above


D.

Note

While you can suggest to the JVM that it might want to run a garbage collection cycle, the JVM is free to ignore your suggestion.

Option B is how to make this suggestion.

Since garbage collection is not guaranteed to run, Option D is correct.




PreviousNext

Related