04. Stack and Heap Memory

A simple comparison

Comparison of Stack and Heap memory

Stack Memory

Heap Memory

Generally, memory is automatically managed by program.

Generally, memory management to be done by programmer.

Traditionally used to stores temporary variables created by each function.

Variables created on the heap are accessible by any function, anywhere in program.

Limit on stack memory size.

No specific limit on heap memory size.

Self cleaning memory.

Memory cleanup required explicitly.

Gophercon - Understanding Allocations: the Stack and the Heap - GopherCon SG 2019

Blog Posts

Last updated