Memory Model: Stack vs Heap
Understand how primitive values and reference objects are stored in memory, how pointer/reference assignments work, and how function calls push frames onto the Stack.
- Stack memory: LIFO order, fast allocation, fixed size per thread
- Heap memory: Dynamic allocation, reference pointer storage, Garbage Collected (Java/Py/JS) or Manual (C++)
a = [1, 2, 3]; b = a; b[0] = 99a is now [99, 2, 3]Understanding where your variables live in RAM is essential for writing bug-free data structures.
- The Call Stack: Stores function execution frames, primitive values (int, double, bool), and object reference pointers.
- The Heap: Stores dynamic data objects, arrays, trees, and linked list nodes.
- When passing a primitive to a function, a copy is pushed to the stack frame.
- When passing an Object/Array, a copy of the reference pointer is passed. Mutating array elements inside the function alters the object on the Heap!
Simulation Under Construction
This algorithm visualization is currently being built by our engineering team. We are ensuring it meets our high-fidelity standards for multi-language parity.