Chapter 16Memory Management MechanicsPaid chapter

The Garbage Collector — Pacing, Assists, GOMEMLIMIT, and Green Tea

Understand how Go's GC paces itself, what GC assists are, why allocation rate is the primary lever, how GOGC/GOMEMLIMIT interact, and what the Green Tea experiment changes.

Launch paywall

This chapter is part of the paid launch. The preview stays visible so readers can evaluate the exact scope before buying.

Included in

Core and Complete. Complete also includes the practical exam and free Go-version updates.

Preview

What this chapter teaches

Common belief

GC pauses are the cost; tune GOGC to fix latency.

What actually happens

GC cost includes concurrent marking, assists, scheduling effects, and stop-the-world pauses. Allocation rate and live-object structure matter alongside GOGC and the soft memory limit.

Mechanisms covered
GOGC (default 100) sets the ratio of new allocation to live heap before the next cycle. GOMEMLIMIT (Go 1.19+) adds a soft memory ceiling.
Allocation rate is the primary lever: reducing allocs/op reduces GC frequency and assist tax. Tuning GOGC/GOMEMLIMIT without reducing allocation rate trades memory for latency.
Green Tea GC (default since Go 1.26; experimental opt-in GOEXPERIMENT=greenteagc on 1.25; opt-out nogreenteagc on 1.26, removed in 1.27): marks small objects at span granularity for spatial locality rather than per-object, with SIMD assistance on recent x86. Expected ~10–40% less GC overhead on GC-heavy programs. This connects directly to scan/noscan locality from Chapter 15.
tracebenchexperiment
One-time purchase

Unlock Chapter 16 and the rest of the course.

Core unlocks every paid chapter and lab. Complete also includes the practical exam and future Go-version updates.

Core
$49

Full course access with the complete mechanics curriculum.

All paid chapters unlocked
One-time purchase
Perfect if you want the material only
Complete
$79
Best value

Best-value launch option with the exam and free Go-version course updates.

Everything in Core
Black Belt practical exam
Free Go-version updates

No subscription or account required. Access is tied to the email entered at Stripe Checkout and can be restored by email.

Free chapter
Escape Analysis — The Compiler's Fragile Decision
Understand how the compiler decides between stack and heap allocation, why the decision is fragile, and how to verify it.
Free chapter
Maps — Swiss Tables, Growth, and Permanent Memory
Understand the Go 1.24+ Swiss Table map layout, why maps don't shrink, and how to design for memory reclamation.