Answer
Garbage collection is automatic reclamation of heap storage for unreachable objects. • The JVM specification does not require one particular collection algorithm. • An object remains reachable through live references and JVM roots. • Garbage collection does not automatically close files, sockets, or other external resources.
Example
Code
Object value = new Object(); value = null; System.gc(); // only a request
Quick Revision
GC reclaims unreachable heap objects; its timing and algorithm are implementation-dependent.