Chapter XIV · Heap & Memory
Heap
The memory heap is an unstructured, large region of computer memory used for dynamic allocation of objects, arrays, and functions.
01 How It Works
Think of an open warehouse storage yard where large boxes of items can be placed in any available open space.
Unlike the structured stack, heap memory stores reference types whose sizes can change dynamically during runtime.
example.js
const user = { name: "Alice", scores: [95, 88] };
1. Complex data structures (objects/arrays) are instantiated.
2. Engine allocates dynamic space in the memory heap.
3. Variables on the stack store memory references pointing to heap addresses.
02 Practical Example
Here is how you might see this concept applied in real-world code:
practical.js
const dataStore = { items: [1, 2, 3], metadata: { active: true } };
Key Takeaway
The memory heap manages dynamic storage allocation for reference types like objects and arrays.