Flowcharts & Processes

Mark-and-Sweep Garbage Collection

Flowcharts & Algorithms diagram · made in Skemio

Flowchart illustrating Mark-and-Sweep GC: start GC, identify stack roots, traverse reachability graph, mark live nodes, sweep unmarked memory blocks to free-list, unmark live nodes, and resume runtime.
Flowchart illustrating Mark-and-Sweep GC: start GC, identify stack roots, traverse reachability graph, mark live nodes, sweep unmarked memory blocks to free-list, unmark live nodes, and resume runtime.

What it shows

  • Roots (stack variables, globals) serve as the starting point for graph traversal.
  • Mark phase flags reachable memory; unreachable islands remain unflagged.
  • Sweep phase reclaims unflagged blocks into a free-list without extra allocations.

The takeaway

Reachability from root references—not reference counts—determines object survival.

More flowcharts & algorithms diagrams