Unloading a DLL from the memory  
Author Message
New-Bee





PostPosted: Common Language Runtime, Unloading a DLL from the memory Top

In my application I use several DLLs. After calling one of them (a managed DLL that calls an unmanaged one), I notice that the memory used jumps from 16MB to 28MB and stays at 28 even after I close its window. I've tried garbage collecting and even the kernel32 method FreeLibrary, which returned 'true', but then made the app crash when attempting using again the DLL I've 'freed'.
Knowing I'll be using more DLLs on this app, is there a way to avoid further memory leak How can I unload DLLs (managed and unmanaged) from the memory Am I missing something here



.NET Development19  
 
 
Ajeeth Kumar





PostPosted: Common Language Runtime, Unloading a DLL from the memory Top

hi,

This happend because we are not properly decrementing the reference counts in the memory. Probably there are two ways of doing this you could use Marshal.ReleaseComObject method or Use Appdomains.

Have a look at the following URL. This might help you.

http://msdn.microsoft.com/library/default.asp url=/library/en-us/odc_of2003_bk/html/officeinteroperabilitych2_part2.asp

Thanks



 
 
nobugz





PostPosted: Common Language Runtime, Unloading a DLL from the memory Top

I doubt you have a real problem. 28MB is chump-change for a CLR hosted app. You cannot unload DLLs unless you load them in an AppDomain and unload the entire AppDomain. Note that Task Manager is not a reliable tool to estimate memory consumption. There are several threads on this forum that talk about alternatives...