In a nutshell
Go uses 2 types of memory allocation methodology.
Stack memory allocation
→ this is for memory allocation exclusively used by function or method call.
Heap memory allocation
→ This happens when the Go compiler determines that pointers won’t live exclusively in function/method call stack. And this decision is made by the process of “Escape Analysis”.
In general, the stack memory allocation is much faster and cheaper than the heap memory allocation, so be careful of using pointers in function/method.