Java Quick Reference
  Language Fundamentals
  Operators and Assignments
  Flow Control and Exceptions
  Declarations and Access Control
  Garbage Collection
  Overloading and Overriding
  Threads
  The java.lang Package
  The java.util Package
  The java.awt Package
  The java.io Package
  References
  Miscellaneous Notes
  Tips & Traps
  Mock Exams

Garbage Collection Certification - Eligibility

  • variables and objects are eligible for garbage collection when they become unreachable
  • following summarizes the normal duration of a declared object or variable
Declaration Duration
static field as long as the class is loaded
instance field for the life of the instance
Array components as long as the array is referenced
Method parameters until method execution ends
Constructor parameters until the constructor execution ends
Exception handling parameters until the catch clause completes execution
Local variables in a for-loop, until the loop completes
in a code-block, until the code block completes
  • any variable set to null automatically becomes eligible for garbage collection
gc and the String pool

You may run across mock exam questions or discussions that state Strings created as part of the String pool are never garbage collected. This may well be true as garbage collection is implementation dependent.

The certification exam will not contain questions that rely on specific implementations of any JVM; for exam purposes it is unlikely you will see any gc questions involving pooled Strings. Just remember once an Object reference has been set to null it is eligible for garbage collection.


Behaviour Eligibility finalize()