Will loading the same DLL multiple times with Assembly.Load cause significant overhead?

The Assembly.Load method loads an assembly into memory and returns an Assembly object. Loading the same DLL file multiple times using Assembly.Load will result in the DLL being loaded multiple times, each time consuming a certain amount of memory space.

In this situation, there will be memory wastage because every time it is loaded, the assembly is copied into memory; assuming the size of the DLL file is 100KB, each load will increase memory usage by 100KB.

Of course, the CLR (Common Language Runtime) caches loaded assemblies to improve loading speed for future use. However, even with caching, reloading the same DLL file repeatedly will still consume a certain amount of memory.

To avoid wasting memory, it is recommended to use a singleton pattern or other methods in the code to ensure that the DLL file is only loaded once.

Leave a Reply 0

Your email address will not be published. Required fields are marked *