How quickly is AppDomain created?

I just discovered that when generating assemblies via Reflection.Emit, the .NET framework keeps references in a static member, which prevents Reflection.Emit classes from not being GC'ed.

I am unable to use DynamicMethod due to limitations. I also generate many assemblies (IronScheme incremental compiler) over the course of a program (maybe 1000+).

Hence, I thought of just handling the code generation in a separate domain and uploading it later (didn't figure out how to handle this).

Does anyone have any experience how expensive it is?

+1


source to share


2 answers


As I understand it, this is a bit slower than spawning a thread.


Been doing some research trying to find a real link for this. So far this is the best I can think of:
http://msdn.microsoft.com/en-us/library/aa159887.aspx



About 2/3 of the way it causes AppDomains to be created "expensive", but then you can say the same about threads in certain contexts - it really depends on what the particular thread is doing when it is created.

Again: I understand that an AppDomain is essentially a thread (or multiple threads) within a process - a logical separator, if you will; so the runtime ensures that certain additional protections are in place that prevent individual AppDomains from communicating with each other. To create a new AppDomain in an existing process (application), the framework has to do all the work associated with creating a new thread, as well as additional additional overhead to set it up in the rest of the application (which could also include loading one or more assemblies into memory) ... After all, AppDomain lives somewhere between thread and process.

+1


source


I would appreciate it for your specific case.



If it turns out to be costly, just create a few of them, use as needed, and re-create new ones in the background to make sure you always have enough unused ones left (a bit like a thread pool, but you recreate them every time to free memory ).

+2


source







All Articles