← all tinkertoys

How garbage collection (mark and sweep) works

Start from the things your program can reach, mark everything they touch, then sweep away whatever was never marked. Each step is one object.

Tweak it

Break it

Normal run: mark from every root, then free only the unmarked objects.

What to notice