Go's Automatic Variable Moving

I prefer programming languages that produce a compilation error, though.

Go's Automatic Variable Moving

It is surprising to know that Go moves variables to the heap based on the life spans of those variables. Programming languages without this feature either produce compile errors (if they are intelligent enough) or simply returns an obsolete memory address of the variable that has already been removed from the stack.

Despite automatic variable moving is a helpful feature, we should keep an eye on the amount of heap memory a Go program is using. That is because memory allocation in the heap and its garbage collection come at a high cost.

Reference

Understanding Allocations in Go
Understand the differences between the stack and heap in Go, and learn about ways of evaluating performance