Skip to content
Computing Medium #gc#copying#cheney

Copying GC (Cheney)

Two semispaces. Live objects copy from from-space to to-space; the rest is reclaimed by reset.

A free, animated copying gc (cheney) you can read here or embed on any website, from Scrollchart.

Copying GC (Cheney)

Copying GC (Cheney Algorithm)Live objects copy to to-space compactly. From-space wiped by pointer reset. Fragmentation is impossible.from-spacereclaimed by pointer reset after copyto-spaceA (live)B (dead)C (live)D (dead)E (live)F (dead)G (live)H (dead)I (live)J (dead)A'C'E'G'I'free ptrnext alloc here(bump pointer)free (contiguous)1. Scan from roots (stack, globals)2. BFS: copy each reachable object to to-space3. Update forwarding pointers in from-space4. Flip: to-space becomes the new from-spaceAllocation CostFree-list search3.2 ns avgBump pointer0.12 ns avg25x faster allocbump pointer vs free-listPropertiesNo fragmentationAllocation: O(1) bumpLive set halves heapUsed in JVM young genCheney 1970 BFS scanTrade-off: 50% of heap is always reserved as to-space. Used for Eden and survivor spaces in JVM, Go scavenger, and V8 Scavenge.

Two halves of memory. A BFS-style traversal copies live objects compactly into to-space, updating forwarding pointers. After the trace, from-space is wiped. Compaction is automatic; allocation is bump-pointer.

Good for

  • CS algorithms courses covering GC design trade-offs
  • JVM internals articles on young-gen scavenging
  • Go runtime deep-dives on garbage collector phases

Source & accuracy

This copying gc (cheney) is an editorial illustration built to represent the concept accurately. Where it shows figures, they are typical or representative values chosen to make the relationship clear, not a single underlying dataset. The diagram and its explainer are reviewed and maintained centrally, and updated over time as understanding improves.

Two Semispaces and a Compacting Sweep

Copying garbage collection (Cheney's algorithm) partitions the heap into two equal-sized semispaces: from-space and to-space. All live objects start in from-space. When memory is exhausted, the garbage collector scans from-space from the roots (global variables, stack frames), marks reachable objects, and copies them to to-space, compacting them into a contiguous region. The entire from-space is then reclaimed.

The beauty of copying GC is that compaction is free: objects are copied in order into to-space, eliminating fragmentation. Every surviving object gets a new address, so the garbage collector must update all references (a scan of the to-space after copying finishes the job).

Trade-offs and Usage

Copying GC wastes half the heap space (to-space is empty until needed). But the algorithm is simple, has excellent cache locality (to-space is compacted), and has predictable latency (proportional to live objects, not total heap size). Languages like Scheme, some Lisp implementations, and the Java HotSpot VM use copying collection for young-generation heaps where most objects die quickly.

The cost of updating all references can be high if references are scattered throughout the heap. Generational garbage collectors pair copying GC on the young generation (where allocation and death are frequent) with a more efficient algorithm on the old generation (where most objects are long-lived). This hybrid approach avoids the space waste of copying the entire heap.

Embed this diagram

Add this animated copying gc (cheney) to your own site. Copy one line of HTML, or use the embed builder for theme and sizing options.

Reference

What this is
A free, embeddable, animated copying gc (cheney) for any website.
Who uses it
Developer blogs, CS educators.
How to embed
Copy one line of HTML. No signup. No watermark. Works in WordPress, Webflow, Ghost, Substack, plain HTML.
File size
iframe embed, ~80 KB gzipped (loads on demand, does not block your page paint).
License
Free forever. Editorial explainer text included; updated centrally over time.

Embed format options

Copy the universal HTML snippet, the WordPress shortcode, or an iframe fallback - see the WordPress plugin page for details. Any format keeps the same Core Web Vitals profile and the same explainer text.

Embed snippet
<div data-scrollchart="gc-copying" data-scrollchart-v="1"></div>
<script src="https://scrollchart.com/embed.js" async></script>

Frequently asked questions

Where can I get a free animated "Copying GC (Cheney)" for my website?
Scrollchart provides "Copying GC (Cheney)" as a free, embeddable animated diagram you can add to any website with one line of HTML. No signup is required and there is no watermark. The diagram and its explainer text are served from scrollchart.com, so the embed stays current without any maintenance on your end.
How do I embed a copying gc (cheney) in a developer or tech blog?
Copy the one-line snippet from the Scrollchart diagram page and paste it into your post HTML. It works in any static site generator, CMS, or hand-coded HTML page. The embed is a thin loader, not an iframe, so the content is fully in your DOM.