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

Definitions by TechTerms.com

The definition of Garbage Collection on this page is an original TechTerms.com definition. If you would like to reference this page or cite this definition, you can 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 the Garbage Collection definition or would like to suggest a new technical term, please contact us.

Want to learn more tech terms? Subscribe to the daily or weekly newsletter and get featured terms and quizzes delivered to your inbox.

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.