FIX: Destructor Not Called When DEBUG_NEW Is Defined (155292)
The information in this article applies to:
- Microsoft Visual C++, 32-bit Editions 4.0
- Microsoft Visual C++, 32-bit Editions 4.1
- Microsoft Visual C++, 32-bit Enterprise Edition 4.2
- Microsoft Visual C++, 32-bit Enterprise Edition 5.0
- Microsoft Visual C++, 32-bit Professional Edition 4.2
- Microsoft Visual C++, 32-bit Professional Edition 5.0
This article was previously published under Q155292 SYMPTOMS
If new is defined as DEBUG_NEW and a call to new is made for a class that
takes a reference to another class in the member initialization, then the
destructor is not called for the referenced class for versions 4.0, 4.1,
and 4.2.
This is illustrated in the output from the following example:
ClassA Constructor
ClassB Constructor
ClassB Destructor
The destructor for ClassA is not called. NOTE: The Visual C++ 5.0 compiler generates the following error if you try
to compile the sample code:
fatal error C1001: INTERNAL COMPILER ERROR
(compiler file 'E:\utc\src\\P2\ehexcept.c', line 516)
RESOLUTION
The best way to work around the problem is to move the new statement to be
within the body of the constructor. For example,
ClassC() {
mClassB = new ClassB("Goodbye");
}
STATUS
Microsoft has confirmed this to be a bug in the Microsoft products listed
at the beginning of this article. This bug has been fixed in Visual Studio
97 Service Pack 3 and Visual C++ 6.0.
For more information, please see the following article in the Microsoft
Knowledge Base:
170365 INFO: Visual Studio 97 Service Packs - What, Where, and Why
Modification Type: | Major | Last Reviewed: | 12/10/2003 |
---|
Keywords: | kbBug kbcode kbCodeGen kbCompiler kbCPPonly kbfix kbVC600fix kbVS97sp3fix KB155292 |
---|
|