Unloading dynamically-loaded assembly

I've come to a case, where, in my application, i need to load the assembly dynamically. Its not a big deal in .net as we can use reflection, adrian have post about this.

Okay, loading the assembly would be a simple task but how about unloading the dynamically-loaded assembly ? it's not that easy, to unload such assembly you need to close its AppDomain, means if they're in one application you need to close the app itself.

If you're confuse about the difference between AppDomain and Application, please read these article :

Some say, we can load each assembly to diferent AppDomain & to unload them just shutdown its AppDomain. Make sense , but later just make things complicated (at least for me). -- better read this blogpost for the details Why isn't there an Assembly.Unload method?.

When my app running, initially it will consume about 20 Megs, loading several assembly ... and now its 80 Megs, can you imagine if the application running all day long, loading assembly without no-clue how to unload them ? by the end of day, i think it will consume hundreds of megs or probably freeze the PC ?

Until i found this magical thing :p ...

Current state, the application consume about 80 Megs and i minimize the application window, turns out the app now consume ONLY 7K !!! WHAT THE ...

I have no technical explanation but maybe thats the beauty of the managed code, you know, better memory management ?

The solution would be simple then, i check the application idleness and if certain interval reach, e.g idle for 15 min, the application will be automatically minimized :D

What do you think ?

Share this post: | | | |
Filed under:

Comments

# ferry said:

You might not be able to unload certain assembly from the AppDomain, but you could unload the whole AppDomain instead =)

I'm not sure what are you using it for, but you could create new AppDomain each time you want to load dynamic assembly into the new AppDomain, do your stuff, and unload the whole AppDomain when it's no longer needed. However, it might cost you additional processing though in creating and disposing the AppDomain.

Friday, September 07, 2007 10:13 AM
# danni said:

"However, it might cost you additional processing though in creating and disposing the AppDomain."

Thats why i said *that* just make thing more complicated :p

Friday, September 07, 2007 12:47 PM