Bird
0
0

Which Java statement correctly requests the JVM to perform garbage collection?

easy📝 Syntax Q3 of 15
Java - Memory Management Basics
Which Java statement correctly requests the JVM to perform garbage collection?
ARuntime.collectGarbage();
BSystem.gc();
CGarbageCollector.run();
DMemory.free();
Step-by-Step Solution
Solution:
  1. Step 1: Recall the standard method

    The standard way to suggest garbage collection in Java is by calling System.gc();
  2. Step 2: Evaluate other options

    Options B, C, and D are not valid Java methods for garbage collection.
  3. Final Answer:

    System.gc(); -> Option B
  4. Quick Check:

    System.gc() is the correct syntax to request GC [OK]
Quick Trick: Use System.gc() to suggest garbage collection [OK]
Common Mistakes:
  • Using non-existent methods like Runtime.collectGarbage()
  • Confusing garbage collection with memory freeing methods
  • Assuming garbage collection is automatic without any method call

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes