From: Greg Clayton (Greg.Clayton_at_[hidden])
Date: 2004-02-06 02:13:13
I have been using the boost::shared_ptr class to add large classes to STL containers as shared pointers. I use many DLLs that all share the same heap (they all use multi-threaded DLL runtimes), and shared_ptr's are passed between DLLs.
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:
void release() // nothrow
long new_use_count = --use_count_;
if(new_use_count != 0) return;
dispose(); // <-- Crash is on function call to virtual "dispose"
the stack backtrace below:
0 - boost::detail::sp_counted_base::release()
1 - boost::detail::shared_count::~shared_count()
2 - boost::shared_ptr<T>::~shared_ptr<T>()
Do I need to fully instantiate and export these template classes from the main DLL (which is DLL "B" in the above example)?
Any hints would be most appreciated.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk