skip to content
Alvin Lucillo

Escape analysis in Go

/ 1 min read

💻 Tech

In Go, it’s preferrable that your program uses the stack versus the heap. If a variable only lives within a function, it’s memory is allocated to a stack. If a variable is accessed outside the function, it’s memory is allocated to the heap. You can check this if your receiver is of type pointer. Another ways is to via this command:

go build -gcflags=-m 

# sample output:
# argument i escapes to heap

What the command is doing is called escape analysis.