Multiple choice technology programming languages

Which of the following is the correct syntax for suggesting that the JVM performs garbage collection?

  1. System.free()

  2. System.setGarbageCollection()

  3. System.setGarbage()

  4. System.gc()

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

System.gc() is the standard method to suggest JVM garbage collection, though it's only a suggestion to the JVM rather than a guarantee. The other options (System.free(), System.setGarbageCollection(), System.setGarbage()) are not valid Java API methods.