From: Russell Hind (rhind_at_[hidden])
Date: 2004-02-06 07:44:24
Greg Clayton wrote:
> I am currently running into an issue where DLL "A" can build up a shared_ptr in a local variable, and hand ownership over to DLL "B" (which stores the shared pointer in a STL container). I get a crash when the STL container class in DLL B later destructs if DLL A has been unloaded. It seems all virtual functions in the vtable of the shared pointers are bogus at this point. The crash occurs when attempting to call the "dispose()" virtual function as shown below:
Are you sure its nothing as simple as:
shared_ptr<T>::~shared_ptr<T> is called from DLL B for a T that was
created in DLL A that has been unloaded. This means the code for Ts
destructor nolonger exists in memory, so when the shared_ptr actually
deletes the T, it tries to call the destructor of T, for which the code
nolonger exists so bang, access violation or whatever.
You can't unload the DLL while objects from that DLL still exist.
Even though DLL B may have its own copy of the code for T, when the
vtable for T was set up in DLL A, its pointers all pointed to code in
DLL A and therefore, when deleted, will try and execute the destructor
code in DLL A which nolonger exists.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk