Understanding Memory Allocation in Go
summary
Explains Go’s memory model: one heap, one stack per goroutine with stacks grown from the heap so goroutines stay lightweight; contrasts new vs literal address semantics and explains make creates underlying array for slices and channels, showing how append may share or copy the backing array. Covers mark-and-sweep GC and the move in Go 1.5 toward concurrent collection, recommends using the testing benchmark (bytes allocated, allocs/op) and pprof profiler, and warns about leaks from unclosed HTTP response bodies.
AI-written summary · about
chapters (19)
- 0:00Introduction
- 1:15Outline
- 2:05Memory Model
- 3:10Heap
- 4:22Stack
- 4:58Stack Example
- 7:05Stack Model
- 8:36Go Stack Model
- 12:23Slices
- 14:51Unpredictable behavior
- 16:41Channels
- 19:18Garbage Collection
- 21:05Concurrent Garbage Collection
- 23:21Solutions
- 24:38Monitoring
- 25:12Benchmarks
- 26:39Bit Packing
- 29:45PPRO
- 31:31Memory Leaks
related talks
30mMemory Management in Go: The good, the bad and the ugly
40mGolang memory footprint
22mUnderstanding Allocations: the Stack and the Heap
30mGo: escape analysis
50mAn insight into Go Garbage Collection
50mUnderstanding the Go runtime
26mGo Stack: Should It Be Moving Like That?
26mRespecting Memory Limits In Go
