Index Ai Academy
Glossary · Phase 7 · Software engineering

Garbage collector

The part of a language runtime that finds memory nobody uses any more and frees it.

How does Python know when a box is no longer needed? It counts the arrows. Every object has a reference count: how many names (and containers) point at it. When the count reaches zero, the memory is freed at once. A rare loop of objects that point at each other is cleaned up later by the garbage collector.

Try it now

Names on the left, objects on the right. Inside add_tag the name tags points at the very same box as mine, so its change shows outside. list(mine) builds a second box, so copy is separate.

Learn it properly

How computers run code · Bits, memory, the processor, and what really happens when Python runs. About 40 minutes.

Other terms from the same lesson

  • bytecode: The simple instruction list Python turns your code into before its virtual machine runs it, one instruction at a time.
  • call stack: The list of functions that are running, newest on top. Each call adds an entry, and each return removes one.
  • compiler: A program that translates code into machine instructions ahead of time, so the result runs fast.
  • interpreter: A program that carries out code as it reads it, instead of translating it all first.
  • reference count: The number of names that point at an object. When it reaches zero, Python frees the object.
Keep learning

More in plain English.

1286 terms in the glossary, each with the lesson that teaches it.

1286 terms

The glossary

Every word you'll meet in AI and machine learning, explained in everyday language.

Phase 7 · lesson 40 min

How computers run code

Bits, memory, the processor, and what really happens when Python runs.

Never trained an AI? Teach a small one to write, right in your browser. It takes about 20 seconds and needs no account. Teach it to write