Garbage collection.
A tidy-up crew that clears away any object nobody is pointing at anymore, so you don’t free memory by hand.
- 1
A program makes lots of objects. Some are still in use; some you’ve quietly stopped needing.
- Anything loose?2
A collector comes by — not to read your objects, just to ask “is anyone still holding this?”
- 3
It starts from the roots and follows every reference, marking all it can reach.
- Nobody’s holding these.4
Whatever no live reference points to is unreachable — and gets swept away.
- 5
That memory goes back on the free pile, ready to be used again.
- Hold still a sec…6
The catch: it runs on its own schedule, and may briefly pause everything to clean up.
Semicolony semicolony.dev/eli5/garbage-collection/comic