Exams Knowledge Hub

MCQs for Competitive Exams, School & College Exams

Module: | Core Architecture, Basics & Control Flow

Q17: Consider the following statements regarding Garbage Collection and object destruction in Java:

1. Executing the 'System.gc()' method guarantees the immediate, forceful execution of the Garbage Collector algorithm to aggressively destroy all currently unreferenced objects in the Heap.
2. The 'finalize()' method is a protected callback method implicitly invoked by the Garbage Collector directly before an object's memory is reclaimed, historically utilized for emergency resource cleanup.
3. Modern Java iterations (from Java 9 onwards) have strictly deprecated the 'finalize()' method mechanism due to severe performance bottlenecks, lifecycle unpredictability, and inherent security risks.

Which of the above statements is/are correct?
A
Only 1 and 2
B
Only 2 and 3
C
Only 1 and 3
D
1, 2, and 3
✅ Correct Answer: B
🎯 Quick Answer:
The correct combination is 2 and 3. Statement 1 is incorrect because 'System.gc()' is merely a polite request or suggestion to the Java Virtual Machine. The JVM retains absolute authority to completely ignore the request if it determines that garbage collection is currently unnecessary or would negatively impact application performance.
Concept Definition: Garbage Collection is the automated daemon process by which the JVM identifies and permanently deletes objects from the Heap memory that are no longer reachable by the executing application.
Structural Breakdown: The garbage collection process involves three standard steps: Marking (identifying unreferenced objects), Sweeping (deleting them), and Compacting (rearranging remaining objects to prevent memory fragmentation). Historical/Related Context: The 'finalize()' method (originating from the Object class) was heavily taught in early 2000s university curricula as Java's equivalent to a C++ destructor.
However, because the GC runs unpredictably, developers found that 'finalize()' was executing too late, causing database connections and file streams to remain dangerously open.
Causal Reasoning: Java 9 deprecated 'finalize()' because it severely crippled Garbage Collector performance.
Objects with 'finalize()' methods require a complex two-pass deletion cycle, forcing the GC to halt application threads longer than necessary.
Modern Java strongly mandates using 'try-with-resources' or the 'Cleaner' API for deterministic resource management.