I have been hitting my head against the wall for the last couple of days trying to figure out the an appdomain issue. I have created a small windows service that runs plugins. The way it works is, each plugin is a dll that gets loaded into it's own seperate appdomain using "CreateInstanceAndUnwrap" and i keep a reference to the appdomain and once the plugin completes, i shut down the appdomain that is created for that plugin.i'm using shadow copy to allow updates to the plugins while they are running in the framework.Ok good till now. It has run for 6 months perfectly untill last week when i decided to put the core functionality of the framework into a seperate DLL also and execute that dll in a seperate appdomain .So the way it works right now is :
Windows service comes up.the core dll is loaded and executed using CreateInstanceAndUnwrap which in turn is responsible for running the plugins in their own seperate appdomains (using CreateInstanceand..)
I have couple of different locations for assemblies : Bin Folder (Bin of the windows service holds only dlls used by the service) Core DLLs Folder (Core dlls get dropped in here) References Folder (any references get dropped in here) Plugins Folder (plugins get dropped in here)
I resolve any unfound dll by hooking up to each appdomain's onassemblyresolve handler. So this means that the dlls can get loaded from over the network.
Now the problem is the windows service ran for one day and the memory went as hight as 1.5G. I created a dump of the memory and seems like loaded modules are only 100MB of the whole 1.5G so i dont know where all this memory is going to. Using debugdiag I saw an alert for heap fragmentation but i have no idea where i should start to diagnose the issue. Usually when the framework runs for a day it consumed something like 100M. Also this is not related to the plugins either as when i rolled back my changes to the framework the memroy usage became normall as before. When i create the appdomains for plugins, i switch the basePath and the bin path of the appdomain to CORE and References folders that have most of the dlls in there in hope that the assembly resolve gets called less often.
I looked at fusion logs and also read a little bit more about load contexts like default,from, and none but im not sure if thats the right path to take.
Any ideas?