Stack vs Heap

When go runtime allocates memory from heap, and when from stack?

Answer

  1. For small objects whose life cycle is only within the stack frame, stack memory is allocated.
  2. For small objects that will be passed across stack frames, heap memory.
  3. For big objects(>32KB), heap memory.
  4. For small objects that could escape to heap but actually inlined, stack memory.