Stack Unwinding

What Does Stack Unwinding Mean?

Stack unwinding is the method used in C++ and similar programming languages when deconstructing function entries to restore or clean up records during run time. This is usually done when control is switched from one record to the calling record or when an exception is discarded and the control is transferred from a try block to a handler in the C++ language.


Techopedia Explains Stack Unwinding

Stack unwinding is automatically done when exiting a process or a block of code in a program. In a program block, objects that are constructed within that block scope cannot be transferred or accessed by another block. This is why when a certain control leaves that program block, all the objects that are declared or constructed within it will be destroyed automatically by destructors. In object-oriented programming, destructors are methods that are called when destroying objects. They use the stack algorithm or the last-in, first-out process. The object that is declared last will be the first one to be destroyed by the destructor. The stack is being cleared or unwound.


Related Terms

Margaret Rouse

Margaret Rouse is an award-winning technical writer and teacher known for her ability to explain complex technical subjects to a non-technical, business audience. Over the past twenty years her explanations have appeared on TechTarget websites and she's been cited as an authority in articles by the New York Times, Time Magazine, USA Today, ZDNet, PC Magazine and Discovery Magazine.Margaret's idea of a fun day is helping IT and business professionals learn to speak each other’s highly specialized languages. If you have a suggestion for a new definition or how to improve a technical explanation, please email Margaret or contact her…