Garbage collection (computer science)

Stop-and-copy garbage collection in a Lisp architecture:[1] Memory is divided into working and free memory; new objects are allocated in the former. When it is full (depicted), garbage collection is performed: All data structures still in use are located by pointer tracing and copied into consecutive locations in free memory.
After that, the working memory contents is discarded in favor of the compressed copy, and the role of working and free memory are exchanged (depicted).

In computer science, garbage collection (GC) is a form of automatic memory management.[2] The garbage collector attempts to reclaim memory that was allocated by the program, but is no longer referenced; such memory is called garbage. Garbage collection was invented by American computer scientist John McCarthy around 1959 to simplify manual memory management in Lisp.[3]

Garbage collection relieves the programmer from doing manual memory management, where the programmer specifies what objects to de-allocate and return to the memory system and when to do so.[4] Other, similar techniques include stack allocation, region inference, and memory ownership, and combinations thereof. Garbage collection may take a significant proportion of a program's total processing time, and affect performance as a result.

Resources other than memory, such as network sockets, database handles, windows, file descriptors, and device descriptors, are not typically handled by garbage collection, but rather by other methods (e.g. destructors). Some such methods de-allocate memory also.

  1. ^ Cite error: The named reference Abelson-Sussman_2016 was invoked but never defined (see the help page).
  2. ^ "What is garbage collection (GC) in programming?". Storage. Retrieved 2024-06-21.
  3. ^ Cite error: The named reference McCarthy_1960 was invoked but never defined (see the help page).
  4. ^ "What is garbage collection (GC) in programming?". SearchStorage. Retrieved 2022-10-17.

From Wikipedia, the free encyclopedia · View on Wikipedia

Developed by razib.in