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

Technology CommunityCategory: GolangWhen go runtime allocates memory from heap, and when from stack?
VietMX Staff asked 5 months ago

Stack memory is allocated:

  • For small objects whose life cycle is only within the stack frame
  • For small objects that could escape to heap but actually inlined

Heap memory is allocated:

  • For small objects that will be passed across stack frames
  • For big objects (>32KB)