Concept Flow - Stack vs heap mental model
Start: Program runs
Function call: push stack frame
Allocate local variables on stack
If new object created
Allocate object on heap
Store reference on stack
No
Function returns: pop stack frame
Heap objects remain until GC cleans
End
This flow shows how function calls create stack frames with local variables, while objects are allocated on the heap with references stored on the stack.