The information in this article applies to:
SYMPTOMSA call to the vector delete operator on a class defined in a DLL calls the destructor for the object only once. This problem occurs only if the destructor is virtual and the DLL itself does not reference the vector memory allocation functions (new [] or delete []). CAUSE
The code generated by the compiler to perform vector deleting of objects is
done by generating a call to an internal function. This internal function
is generated by the compiler.
Ends up being basically the same as:
RESOLUTIONTo work around this problem, you must force your DLL to reference the vector deleting destructor. The memory allocation functions don't actually need to be called. The compiler just needs to see them. This can be done by generating a dummy function that is never called but that is linked in to the DLL. For example:
The reference to the static variable initialization (pFunc) forces the
function ForceVectors to be linked in. This then forces the DLL to have the
vector deleting destructors for the classes (CMyClass and CMyOtherClass).
Place this code in any module in your DLL.
STATUSMicrosoft has confirmed this to be a bug in the products listed at the beginning of this article. This bug was corrected in Visual C++ version 5.0 to generate correct behavior in the case where the entire class is exported. The bug (and workaround) remains for the case where the class is not exported, but individual class members are exported.
Keywords : kbCompiler kbVC100bug kbVC150bug kbVC200bug kbVC400bug kbVC410bug kbVC420bug kbVC500bug kbVC600bug |
Last Reviewed: July 27, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |