> For the complete documentation index, see [llms.txt](https://book.codewithgo.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://book.codewithgo.com/stack-and-heap-memory.md).

# 04. Stack and Heap Memory

### 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

{% embed url="<https://www.youtube.com/watch?v=ZMZpH4yT7M0>" %}
Like C, Go uses both stack and heap memory. How can a Gopher know which is being used?&#x20;
{% endembed %}

### Blog Posts

{% embed url="<https://www.ardanlabs.com/blog/2013/07/understanding-pointers-and-memory.html>" %}
