It turns out that this is an ATL implementation issue.
The server uses a global instance of the CComModule class. When CComModule::DllClassObject() is called, it creates an instance of the factory class and caches it in the map referenced by the CComModule object. So in fact, the CComModule object belongs to the factory class. When the CComModule runs the destructor, it does not release cached class factories.
To free all cached class factories of CComModule::Term() , the method must be called before the server is unloaded. IMO the purest way to achieve this is to output from CComModule and call CComModule::Term() in the destructor of the derived class.
sharptooth
source share