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, Complete, and Team. 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

STW pauses are sub-millisecond; the real latency cost is GC assists — your allocating goroutines forced to do mark work. The primary lever is allocation rate, not GOGC.

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 (Go 1.25, experimental, GOEXPERIMENT=greenteagc): marks at memory-page granularity for spatial locality rather than per-object. Many workloads spend ~10% (up to ~40%) less time in GC. Planned to become the default in Go 1.26. This connects directly to scan/noscan locality from Chapter 15.
tracebenchexperiment
Email-first checkoutUnlock Chapter 16

Unlock Chapter 16 and the rest of the course.

Start with your email, then continue to Lemon Squeezy checkout. Core unlocks the paid chapters, Complete adds the exam and free Go-version updates, and Team gives you 5 seats.

Choose a plan

You'll head to Lemon Squeezy for secure checkout. Global tax is handled there. No subscription. Complete also includes the practical exam and free Go-version updates.

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.