See Garbage collection run
Garbage collection frees the memory of objects that the program can no longer reach. The program allocates objects but never frees them, and the runtime finds the dead ones. Use the buttons or the keys: Space plays and pauses, the arrow keys step, Home and End jump.
DROP(x) ▷ reference counting: one reference to x goes away- 1
count(x) ← count(x) − 1 - 2
if count(x) = 0 then - 3
for each reference from x to an object y do DROP(y) - 4
free x COLLECT() ▷ tracing: mark from the roots, then sweep- 5
colour each object of the heap white - 6
for each root r do - 7
if r refers to a white object y then colour y grey - 8
while some object is grey do - 9
take a grey object x - 10
for each reference from x to an object y do - 11
if y is white then colour y grey - 12
colour x black ▷ no black object refers to a white object - 13
for each object x of the heap do ▷ the sweep - 14
if x is white then free x - 15
else colour x white ▷ ready for the next collection
Read the full page about Garbage collection. To put this player on your site, use <iframe src="https://programming.tamnd.com/embed/garbage-collection/" width="100%" height="520"></iframe>.