EMBEDDED SYSTEMS & MICROCONTROLLERS · PAGE 53
Stack and Heap Usage
Where small chips run out of RAM.
The stack holds return addresses, function arguments and local variables, and it grows with each nested call. Large local arrays and deep recursion are the usual causes of overflow.
The heap supplies memory on request through functions like malloc. On a tiny chip, repeated allocation and freeing can fragment it until a request fails. Most small designs avoid the heap completely.
Test by filling unused stack with a known pattern and checking how much remains untouched.