Microsoft KB Archive/92500

= PRB: exit Function Does Not Clean Up Nonstatic Objects =

Article ID: 92500

Article Last Modified on 7/5/2005

-

APPLIES TO


 * Microsoft Visual C++ 1.0 Professional Edition
 * Microsoft Visual C++ 1.5 Professional Edition
 * Microsoft Visual C++ 1.51
 * Microsoft Visual C++ 1.52 Professional Edition
 * Microsoft Visual C++ 2.0 Professional Edition
 * Microsoft Visual C++ 2.1
 * Microsoft Visual C++ 4.0 Standard Edition
 * Microsoft Visual C++ 4.1 Subscription
 * Microsoft Visual C++ 4.2 Enterprise Edition
 * Microsoft Visual C++ 5.0 Enterprise Edition
 * Microsoft Visual C++ 6.0 Enterprise Edition
 * Microsoft Visual C++ 4.2 Professional Edition
 * Microsoft Visual C++ 5.0 Professional Edition
 * Microsoft Visual C++ 6.0 Professional Edition
 * Microsoft Visual C++ 6.0 Standard Edition

-



This article was previously published under Q92500



SYMPTOMS
When an application calls the exit, _exit, _cexit, or _c_exit functions, the destructors for any temporary or automatic objects that exist at the time of the call are not called. The text below provides a sample program to demonstrate this behavior.



MORE INFORMATION
An automatic object is an object that is defined in a function where the object is not declared to be &quot;static.&quot; A temporary object is an object created by the compiler.

To destruct an automatic object before calling exit, explicitly call the destructor for the object, as follows:   myObject.myClass::~myClass;

Sample Code
/* Compile options needed: for 16-bit - /f /Od /Zi
 * for 32-bit - none


 * 1) include 
 * 2) include 

class myClass {  int nVal;

public: myClass; void View {cout << nVal << &quot;\n&quot;;}; ~myClass; };

myClass::myClass {  nVal = 99; }

myClass::~myClass {  cout << &quot;Destructor has been called\n&quot;; }

void main(void) {  myClass myObject;

myObject.View;

// Remove the comment from the next line to call the destructor // myObject.myClass::~myClass;

exit(0); }

Additional query words: 8.00 8.00c 9.00 9.10

Keywords: kblangcpp kbprb KB92500

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.