Stack Unwinding

Why Trust Techopedia

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
Technology Expert
Margaret Rouse
Technology Expert

Margaret 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 IT definitions have been published by Que in an encyclopedia of technology terms and cited in articles by the New York Times, Time Magazine, USA Today, ZDNet, PC Magazine, and Discovery Magazine. She joined Techopedia in 2011. Margaret's idea of a fun day is helping IT and business professionals learn to speak each other’s highly specialized languages.