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
Use your own input
Type the input as JSON, in the same form as a preset.