Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 682
Joe Avatar asked Dec 18 '22 02:12

Joe


1 Answers

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.

like image 53
John Dibling Avatar answered Dec 24 '22 00:12

John Dibling