Does COM automatically unload DLLs when there are no more object references?
c++, com, scripting, vb6, vbscript
Solution
Yes, but not in a deterministic way. Windows periodically asks every loaded DLL "is it safe to unload you now?" Any DLL that responds "Yes" is unloaded.
Note a remark from MSDN :
If a DLL loaded through a call to CoGetClassObject fails to export DllCanUnloadNow, the DLL will not be unloaded until the application calls the CoUninitialize function to release the OLE libraries.
See this Old New Thing article.
Problem
For example, in language X: ``` let x = CreateOject( "MyProgID" ) x.LateBoundCall() x.Release() // (or setting x to Nothing in VB-like language, etc) ``` What happens to the DLL `MyProgID` lives in? Does COM unload DLLs automatically? EDIT This is assuming that the code above is in an executable that does not expose any COM.