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 ?