Garbage Collection

In computer science, garbage collection is a type of memory management. It automatically cleans up unused objects and pointers in memory, allowing the resources to be used again. Some programming languages have built-in garbage collection, while others require custom functions to manage unused memory.

A common method of garbage collection is called reference counting. This strategy simply counts how many references there are to each object stored in memory. If an object has zero references, it is considered unnecessary and can be deleted to free up the space in memory. Advanced reference counting detects objects that only reference each other, which indicates the objects are unused by the parent process.

Garbage collection may also be done at compile-time, when a program's source code is compiled into an executable program. In this method, the compiler determines which resources in memory will never be accessed after a certain time. It can then add instructions to automatically deallocate those resources from memory. While this is an effective way to eliminate unused objects, it must be done conservatively to avoid deleting references required by the program.

Garbage collection is an important part of software development since it keeps programs from using up too much RAM. Besides helping programs run more efficiently, it can also prevent serious bugs, such as memory leaks, that can cause a program to crash.

Updated January 20, 2016 by Per C.

quizTest Your Knowledge

A variable that controls access to one or more resources is also called what?

A
A decryptor
0%
B
A semaphore
0%
C
An access value
0%
D
A constant
0%
Correct! Incorrect!     View the Semaphore definition.
More Quizzes →

The Tech Terms Computer Dictionary

The definition of Garbage Collection on this page is an original definition written by the TechTerms.com team. If you would like to reference this page or cite this definition, please use the green citation links above.

The goal of TechTerms.com is to explain computer terminology in a way that is easy to understand. We strive for simplicity and accuracy with every definition we publish. If you have feedback about this definition or would like to suggest a new technical term, please contact us.

Sign up for the free TechTerms Newsletter

How often would you like to receive an email?

You can unsubscribe or change your frequency setting at any time using the links available in each email.

Questions? Please contact us.