I'm using an AppDomain in order to load assemblies and then unload them.
However, I'm having a very strage problem. After the AppDomain is unloaded - I can still see in process explorer that some assemblies are loaded multiple times! Why are there remainders of the loaded assemblies? Doesn't an AppDomain.Unload frees all the AppDomain's loaded memory?
You can see in the attached image:
Total AppDomains are 3 (I created 3 AppDomains in the process's life-cycle)
AppDomains: 1 (Currently only 1 AppDomain exists)
And for some reason, as you can see in the loaded DLL section bellow - Assemblies are loaded multiple times into the process..
Code:
AppDomain fetcherDomain = AppDomain.CreateDomain("StatusFetcher");
try
{
var fetcher = (LocalStatusFetcher)fetcherDomain.CreateInstanceFromAndUnwrap(Assembly.GetExecutingAssembly().CodeBase, typeof(LocalStatusFetcher).FullName);
//doing some other stuff that is not interesting...
}
finally
{
AppDomain.Unload(fetcherDomain);
}
And yes, LocalStatusFetcher does inherit MarshalByRefObject...