Is there a way to deallocate variables and/or objects created on the stack? I am specifically talking about the stack not the heap.
I do not want to debate whether this
Every time you return from a function, any memory allocated on the stack by that function is deallocated. If you need to reduce the scope of a variable for some reason, you can just make a new smaller scope by creating a block with {}
.
void function(void)
{
int x;
{
int y;
} // scope of y ends
} // scope of x ends