Garbage Collection

Garbage collection is the automatic management of a program’s memory. Instead of asking the programmer to track which pieces of storage are still in use and to free the rest by hand, the system itself finds memory that can no longer be reached and makes it available again.

The idea was first put into practice for LISP. In his “History of LISP,” John McCarthy describes garbage collection as the approach in which “storage is abandoned until the free storage list is exhausted, the storage accessible from program variables and the stack is marked, and the unmarked storage is made into a new free storage list.” Memory that nothing points to is treated as garbage and reclaimed.

McCarthy’s account notes that once garbage collection had been chosen as the design, its actual implementation could be postponed because only small examples were being run at first. The technique was implemented for the LISP system as it matured around 1959 and 1960.

By moving the bookkeeping of memory from the programmer into the language system, garbage collection removed a large class of bugs and became a standard feature of many later languages, even though the manual approach of allocating and freeing memory remained common in lower-level languages for decades.