Are destructors run when calling exit()?

WilliamKF picture WilliamKF · Aug 14, 2011 · Viewed 20.7k times · Source

Possible Duplicate:
Will exit() or an exception prevent an end-of-scope destructor from being called?

In C++, when the application calls exit(3) are the destructors on the stack supposed to be run to unwind the stack?

Answer

Cheers and hth. - Alf picture Cheers and hth. - Alf · Aug 14, 2011

No, most destructors are not run on exit().

C++98 §18.3/8 discusses this.

Essentially, when exit is called static objects are destroyed, atexit handlers are executed, open C streams are flushed and closed, and files created by tmpfile are removed. Local automatic objects are not destroyed. I.e., no stack unwinding.

Calling abort lets even less happen: no cleanup whatsoever.