Garbage collection (computer science)

Edit · View history

Garbage collection (computer science)

Garbage collection (GC) is a form of automatic memory management in computer programming. It automatically reclaims memory that was previously allocated by a program but is no longer referenced, freeing it for reuse. Garbage collection relieves programmers from manual memory management tasks such as calling free or delete, reducing errors like memory leaks, dangling pointers, and double frees. It is a key feature of many high-level languages including Java, C#, Python, and Go.

History

The concept of garbage collection originated in the 1950s with the Lisp language, developed by John McCarthy at MIT. The first implementation used a simple mark-and-sweep algorithm. In the following decades, researchers developed more sophisticated techniques such as reference counting, copying collectors, and generational collection. The 1970s and 1980s saw theoretical advances like the Baker treadmill and the Boehm collector, which made GC practical for languages like C and C++. Modern systems often combine multiple strategies to achieve low pause times and high throughput, as seen in the Java Virtual Machine and .NET runtime.

Techniques

Advantages and disadvantages

Garbage collection increases programmer productivity by eliminating manual memory management and reducing bugs. It also enables safer memory-safe languages. However, it can introduce unpredictable pauses (stop-the-world events) and overhead in CPU and memory, which may be unsuitable for real-time computing or systems with limited resources. Modern collectors use concurrent and incremental techniques to mitigate these issues.

See also