4

I am using AppDomain to isolate assembly loading and in some cases, the AppDomain.Unload(customDomain) never return (I suspect this is due to some thread usage).

I plan to put the AppDomain.Unload call in a separate Task, time it, and if nothing happen in x milliseconds, I just move on. I could also restart the process but it is more costly. So how bad is AppDomain leaking ?

For the context: I programmaticaly change an assembly, write it on disk, load it in a new appdomain, run some tests on it then I unload the appdomain and restart the same routine with a new version of the assembly.

shorty_ponton
  • 454
  • 4
  • 14
  • 1
    Have a look here: http://stackoverflow.com/questions/5493843/how-to-gracefully-unload-a-child-appdomain-that-has-threads-running – Maximilian Riegler Apr 27 '16 at 10:52
  • 1
    @rinukkusu thk you, I saw this one but I can't change the loaded code to comply with my usage because the whole point of my program is to programmaticaly change the code in order to create errors, these changes are precisely define and I can't edit by hand the tested code. – shorty_ponton Apr 27 '16 at 10:58
  • 1
    @rbm yep, I don't like leaks but I wonder what are the implication of AppDomain leaking – shorty_ponton Apr 27 '16 at 10:59
  • 1
    The ill effects are memory usage, files being locked and probably some CLR data structures getting slower over time (e.g. o(n^2)). Are you thinking of something else? – usr Apr 27 '16 at 11:26
  • @usr mmmm I expected growing memory usage, but I didn't thought about locked file ty! I think this kind of issue will be partly avoided, because by default, my program test multiple versions of the assembly in parallel, so for this kind of concurrency issue, I expect the user (I have faith :D) to explicitly run the program in non parallel mode, otherwise the program won't crash but it may produce false positive results. I don't think I'll try to go further on this problem in my code, because I would have to deal with all kind of concurrency issue then (like DB access) – shorty_ponton Apr 27 '16 at 11:41

0 Answers0