As we all know, when a function returns, stack-allocated objects would be reclaimed and the associated destructors would be invoked before that. My question is: how is a memory location determined to represent objects so that we can call the destructor? And is there any run-time overhead incurred to do this?
As we all know, when a function returns, stack-allocated objects would be reclaimed and
Share
Memory location does not determine when the constructor gets called. The compiler knows which variables are allocated on the stack and creates the appropriate code to call the corresponding destructors.
At least, they are normally on the stack. The point is the same logic could be used regardless of where the memory was stored. Being stored on the stack simply means that they need to be called one way or another.