0
Are local variables in function automatically deleted when the function terminates?
Are local non-pointer variables in functions automatically deleted when the function stops or they continue to occupy memory in the stack? If I use the same function many times does the occupied space increase?
1 Antwort
+ 3
Yes they will be deleted. Every time you call a function you put a "stack frame" on top of the stack where all the local variables live in, and when the function is done, the stack frame will be "teared down".
The stack is also usually limited in size. If you keep tacking too many frames onto the stack - for example when a recursive function goes rogue and keeps calling itself - then a "stack overflow" occurs and your program blows up.