Only some of the variables are lost when they go out of scope. in C/C++ the simple stuff arrays, ints, reals floats and so do disapper
when they go out of scope as they are created on the stack.
However object are created on the heap and need to be expilcitly destroyed before they go out of scope. If you don't when the heap is used up.
Mark
PS there are many other ways to run out of memory why not post your code.