# clearing control stack?

**URL:** <https://community.unix.com/t/clearing-control-stack/166857>\
**Category:** Programming\
**Created:** [November 15, 2006, 3:30am UTC](https://community.unix.com/t/clearing-control-stack/166857 "2006-11-15T03:30:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![naan](https://community.unix.com/letter_avatar/naan/32/5_5575768a8748004e209b776fc1b2916d.png) [@naan](https://community.unix.com/u/naan)\
**Post date:** [November 15, 2006, 3:30am UTC](https://community.unix.com/t/clearing-control-stack/166857/1 "2006-11-15T03:30:41Z")

</div>

Hi,

Can someone please explain how is the control stack cleared when we exit from a function?or who clears the rescords in the control stack?

Thanks

---

<div class="post-metadata">

**Author:** ![jim\_mcnamara](https://community.unix.com/letter_avatar/jim_mcnamara/32/5_5575768a8748004e209b776fc1b2916d.png) [@jim\_mcnamara](https://community.unix.com/u/jim_mcnamara)\
**Post date:** [November 15, 2006, 6:40am UTC](https://community.unix.com/t/clearing-control-stack/166857/2 "2006-11-15T06:40:11Z")

</div>

The stack is never "cleared". When a function exits, the stack pointer is "aimed" at the return address. The stuff that was pushed onto the stack for the exited function remains there, until it is overwritten by the next function call.

This is why uninitialized automatic variables(the ones whose memory is allocated on the stack) contains leftover garbage from the previous function that was stored at the address on the stack.
