# Garbage Collection

> The language finds memory no one uses now. Then it frees it.

**Field:** Software Development  
**Category:** Compilers & Runtimes  
**Also known as:** GC, Garbage Collector, Automatic Memory Management

## Think of it like

Think of it like a cleaner going room to room. They throw out what nobody uses.

## Definition

Garbage collection is when the language frees memory once nothing uses it. A part of the runtime, the garbage collector, looks for data that no part of the program can reach. It then gives that memory back so it can be used again. Java, C#, Go, JavaScript and Python all work this way. The cost is extra work in the background, and sometimes short pauses.

## Example

Lucy's JavaScript function builds a big list, uses it and returns. Nothing points at the list now. The garbage collector frees it a moment later.

## Why it matters

It gets rid of a whole kind of bug, like freeing the same memory twice. So most big languages have it.

## Common mistake

Thinking it stops every memory leak. It cannot free data your code still points at, even by mistake.

## Three principles

- **Finds unreachable data.** Nothing points at it.
- **Frees it for you.** No free call needed.
- **Costs some time.** Work and short pauses.

## Related terms

- [Memory Management](https://learn.benibix.com/term/development/memory-management)
- [Heap Memory](https://learn.benibix.com/term/development/heap-memory)
- [Memory Leak](https://learn.benibix.com/term/development/memory-leak)
- [Java](https://learn.benibix.com/term/development/java)
- [Memory Safety](https://learn.benibix.com/term/development/memory-safety)

## Told apart from

- [Memory Safety vs Garbage Collection](https://learn.benibix.com/compare/memory-safety-vs-garbage-collection): A garbage collector frees memory you are done with. Memory safety means code can never reach memory that is not its own. Rust is safe without one.

---

Source: https://learn.benibix.com/term/development/garbage-collection
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-19
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
