1. DROP(x) ▷ reference counting: one reference to x goes away
  2. 1count(x) ← count(x) − 1
  3. 2if count(x) = 0 then
  4. 3for each reference from x to an object y do DROP(y)
  5. 4free x
  6. COLLECT() ▷ tracing: mark from the roots, then sweep
  7. 5colour each object of the heap white
  8. 6for each root r do
  9. 7if r refers to a white object y then colour y grey
  10. 8while some object is grey do
  11. 9take a grey object x
  12. 10for each reference from x to an object y do
  13. 11if y is white then colour y grey
  14. 12colour x black ▷ no black object refers to a white object
  15. 13for each object x of the heap do ▷ the sweep
  16. 14if x is white then free x
  17. 15else colour x white ▷ ready for the next collection
0 / 0
Use your own input

Type the input as JSON, in the same form as a preset.

Open the full player

Garbage collection on Programming