Does COM automatically unload DLLs when there are no more references to objects?

For example, in the language X:

let x = CreateOject( "MyProgID" ) x.LateBoundCall() x.Release() // (or setting x to Nothing in VB-like language, etc) 

What happens with the MyProgID DLL? Is the COM DLL unloaded automatically?

EDIT

This assumes that the above code is in an executable that does not provide any COM code.

+4
source share
2 answers

Yes, but not in a deterministic way. Windows periodically asks each loaded DLL " Is it safe to unload you now ?" Any DLL that says yes is unloaded.

Note the note from MSDN :

If the DLL is loaded through a call to CoGetClassObject, DllCanUnloadNow cannot be exported, the DLL will not be unloaded until the application calls the CoUninitialize function to release the OLE library.

See the Old New Thing article.

+10
source

you need to manually release the resources used by COM objects. they use an internal reference counter to save the number of links to the component. if the component still has refcounter> 0, then the dll will not be unloaded and resources will not be freed.

+2
source

Source: https://habr.com/ru/post/1303479/


All Articles