do variables die in function

This is a discussion on do variables die in function within the C++ Programming forums, part of the General Programming Boards category; if varianbles are declared within a function, do they die when the function finish?...

The memory space will still be avialable until you delete it, however any local pointers you have in the function will be destroyed when the function ends, so unless you are saving the pointer somehow (return value or static) then that memory space is effectivaly lost.

I have run experiments on an xp machine.
I ran a program with initialization and declaration of a variable inside a function.
Local scope without being declared as static.
I monitored the memory usage per the system log.
The memory was still being used by the system after the exit of the function.
It didn't release the memory back to the system resource pool until after the program itself was dead. I think the adress that keeps track of the memory is dead after the function ends, but the memory itself is still concidered active in the program until the program itself dies. This could all be system dependent though. Windows does some weird things sometimes.