
Stack

- First-In-Last-Out structure.
- Stores local variables, reference variables, as it lives for short lifetime.
- It only stores simple data types like primitives(e.g. int, double, ..) . It doesn’t save complex data types like objects.
- Each Thread has its own Stack
- Data on a stack cannot be accessed from other threads
Heap

- Objects are stored on the heap.
- Heap is shared across all threads.
Example of Stack and Heap



Leave a comment