Suppose I have two total separate .NET apps, Foo.exe
and Boo.exe
, both of which are using the same library TestLib.dll
which is located in the bin folder of Foo and Boo (two copies).
Will .NET load both of these dlls, wasting size_of_dll * 2
size of RAM or it will check strong assemblies names, sizes etc... and load and load only one of the two assemblies?
You are correct that a feature of DLLs is that multiple processes both using that DLL can share certain sections in order to reduce memory usage (this is a Windows feature and is not specific to .Net), however I'm fairly certain that for this to work the two processes must load the same physical DLL on disk, in which case this won't be happening for the scenario you describe.
If you instead installed into a common location (e.g. the GAC) then Windows would be able to share certain portions of the DLL across multiple processes in order to save memory. In the case of .net assemblies you also need to NGen the assembly in order to take advantage of this
Note that the amount of memory "saved" is not size_of_dll
as certain parts of that DLL image cannot be shared, namely any section of that DLL which may be modified. These sections are still duplicated across multiple processes to ensure that applications don't accidentally modify each others data.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With