Multiple choice technology programming languages

  1. rbo = new ReallyBigObject(); 12. // more code here 13. rbo = null; 14. /* insert code here */ Which statement should be placed at line 14 to suggest that the virtual machine expend effort toward recycling the memory used by the object rbo?

  1. System.gc();

  2. Runtime.gc();

  3. System.freeMemory();

  4. Runtime.getRuntime().growHeap();

  5. Runtime.getRuntime().freeMemory();

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

System.gc() is a method that suggests to the Java Virtual Machine that it would be advantageous to run the garbage collector. The JVM may choose to ignore this suggestion, but it's the standard way to programmatically request GC effort. The other options are incorrect: Runtime.gc() does not exist (gc() is a method on Runtime, but you need Runtime.getRuntime().gc()), System.freeMemory() does not exist, and Runtime.getRuntime().growHeap() and Runtime.getRuntime().freeMemory() are not standard Java methods.