Go is garbage collected; it manages its own memory with a computational cost. Writing an efficient application requires knowledge of its memory model and internals in order to reduce the garbage collector's work and increase general performance.
Understanding memory management
Stack and heap
Memory is arranged into two main areas – stack and heap. There is a stack for the application entry point function (main), and additional stacks are created with each goroutine, which are stored in the heap. The stack is, as its name suggests, a memory portion that grows with each function call, and shrinks when the function returns. The heap is made of a series of regions of memory that are dynamically allocated...