~/talk

Understanding Allocations: the Stack and the Heap

Talkat GopherCon Singapore 2019 · on Friday, 2019-05-03· [go]
slides:none on file

Go decides at compile time whether locals live on the stack or heap and never moves them at runtime; taking an address that’s used after return causes an escape so a local like X = 42 returned by reference ends up on the heap, whereas passing a pointer down usually stays on the stack. Three common heap triggers are referenced after return, too large for the stack or unknown size at compile time (eg a 32‑byte slice). Ask the compiler with go build GC flags -M and inspect runtime behavior with pprof and the tracer.

AI-written summary · about

  1. 0:00Introduction to allocations
  2. 0:22Stack vs heap basics
  3. 1:29Does allocation location matter?
  4. 3:38Stack memory walkthrough
  5. 6:26Pointers and stack memory
  6. 7:50Sharing down stays on stack
  7. 8:13Sharing up escapes to heap
  8. 10:45Escape analysis explained
  9. 12:31Compiler flags for tracking
  10. 14:38When values go to heap
  11. 15:46Common heap-allocated values
  12. 17:09Stack vs heap in slices
  13. 18:56Key takeaways summary
  14. 20:20Tools and final advice
  15. 20:43Q&A on performance vs clarity
~/search
type to search 6,249 conferences, 138,987 speakers and 185,172 talks
~/help
cmdctrl k
search every conference, speaker and series
/
focus the filter search
h
home
c
conferences
s
speakers
e
series
t
light / dark — the status bar button does the same
?
this help
esc
close this, then clear every filter — or just the search, while you are typing in it

Ignored while you are typing. Pages without a filter rail have no search to focus.