Skip to content

Memory: resources

Level: 301 · for whoever wants the primary sources behind this chapter, and the books' chapter names

One line: The garbage collector guide, the spec's size and alignment rules, the runtime, runtime/debug, unsafe and weak packages, and the release notes that added the memory limit, cleanups and weak pointers — plus which chapters of the books on the shelf cover them.

Primary sources

Books

  • Alan A. A. Donovan and Brian W. Kernighan, The Go Programming Language (Addison-Wesley, 2015) — chapter 2, "Program Structure", section 2.3.4, "Lifetime of Variables" (escape, in two pages); chapter 13, "Low-Level Programming", section 13.1, "unsafe.Sizeof, Alignof, and Offsetof".
  • Jon Bodner, Learning Go, 2nd ed. (O'Reilly, 2024) — chapter 6, "Pointers": "Pointers Are a Last Resort", "Pointer Passing Performance", "Slices as Buffers", "Reducing the Garbage Collector's Workload" and "Tuning the Garbage Collector".
  • Katherine Cox-Buday, Concurrency in Go (O'Reilly, 2017) — chapter 3, "Go's Concurrency Building Blocks", the section "Goroutines", which measures a goroutine's memory and works out how many fit.
  • James Cutajar, Learn Concurrent Programming with Go (Manning, 2024) — chapter 2, "Dealing with threads", the section "What goes on the stack space?".
  • Burak Serdar, Effective Concurrency in Go (Packt, 2023) — chapter 2, "Go Concurrency Primitives", the section "Goroutines", on closures and the variables that escape to the heap because a goroutine captures them.
  • Go in Practice, 2nd ed. (Manning, 2025) — chapter 1, "Getting started with Go", the note on GOGC=off; the chapter promises more on collector control in chapter 13, "Reflection, code generation, and advanced Go", whose sections are about reflection, tags, code generation and C.

Not on the shelf

  • Teiva Harsanyi, 100 Go Mistakes and How to Avoid Them (Manning, 2022) — publisher's page ↗; a chapter on optimizations covers escape analysis, sync.Pool and GC tuning.
  • Bartłomiej Płotka, Efficient Go (O'Reilly, 2022) — publisher's page ↗; memory, the allocator and the collector from a profiling angle.

Talks and videos

  • Jacob Walker, Understanding Allocations: the Stack and the Heap, GopherCon Singapore 2019 — video ↗. Escape analysis explained with -gcflags=-m.
  • Rick Hudson, Go GC: Solving the Latency Problem, GopherCon 2015 — video ↗. The concurrent collector's design, as it shipped in Go 1.5.
  • Dave Cheney, High Performance Go Workshop, GopherCon 2019 — notes ↗. Escape analysis, inlining and the collector, with exercises.

Read with care

  • "A goroutine's stack starts at 8 KB" or "4 KB" — true for Go 1.2 and 1.3; it has been 2 KB since 1.4, and since 1.19 the runtime adapts the starting size to recent goroutines.
  • "Go's collector is stop-the-world" — the collector has been concurrent since Go 1.5; the two brief pauses per cycle are the point of the 2015 and 2018 talks above.
  • runtime.SetFinalizer as the way to release a resource — still works, but the package's own documentation now steers new code to AddCleanup, and the finalizer's handing back of the object is what made it error-prone.
  • "GOGC is the only knob" — true before Go 1.19; GOMEMLIMIT is the second, and GOGC=off with a limit is a supported configuration.
  • "Pass pointers to avoid copying" — a 24-byte struct copies faster than it allocates; Escape analysis decides stack or heap measures it, and Bodner's "Pointers Are a Last Resort" says the same.
  • Any transcript of -gcflags=-m — the wording changes between compiler versions and inlining changes the verdicts; the keys in this chapter are go1.25's, with //go:noinline where a stable transcript needed it.
  • "make([]T, n) with a variable n always allocates" — true until Go 1.25, which keeps a small one in the frame.

Checked 2026-09-23.