Garbage Collection
Subject: Computer and Technology noun /ˈɡɑːr.bɪdʒ kəˌlɛk.ʃən/ 1 definition
- memory-management
- runtime-systems
- programming-languages
- computer-science
-
Definition (noun)
Entry #6 · UpdatedGarbage Collection (GC) is an automatic memory management mechanism used by language runtimes to identify and reclaim heap memory occupied by objects that a running program can no longer access. Unlike manual memory management, it removes the burden of explicit deallocation to prevent bugs such as dangling pointers and double frees, while trading deterministic cleanup timing for runtime tracking or pause-time overhead.
Common Types
Mark-and-Sweep: Traverses the object graph from active root references to mark reachable objects, then sweeps away unmarked memory blocks so the allocator can reuse them.
Reference Counting: Stores a counter on each object tracking active pointers to it, immediately reclaiming the object when its count reaches zero unless cyclic references remain.
Generational Garbage Collection: Partitions the heap by object age into young and old generations, collecting short-lived objects frequently in fast minor cycles while scanning older objects less often.
Concurrent Garbage Collection: Executes most object marking and memory reclamation alongside application threads to minimize stop-the-world pauses in latency-sensitive runtimes such as the JVM, Go, and .NET.
Example
When a Java web service finishes handling an HTTP request, the temporary request, JSON buffer, and response objects allocated for that call lose all references from active stack frames. During the next minor collection cycle, the JVM garbage collector scans the young generation, detects those unreachable objects, and reclaims their heap space for incoming requests without explicit
freecalls.