views:

282

answers:

2

I have just discovered that if generating assemblies via Reflection.Emit, the .NET framework keeps references in a static member that prevents Reflection.Emit classes not to be GC'ed.

I cannot use DynamicMethod due to limitations. I also generate a lot of assemblies (incremental compiler of IronScheme) over the course of a program (could be 1000+).

Hence, I was thinking to just handle the code generation in a separate domain, and unload it later (have not decided how to handle this).

Does anyone have any experience how expensive this would be?

+1  A: 
Joel Coehoorn
That would be good news indeed! I have just discovered tons more references from it, it really does mess up the GC :)
leppie
Now to figure out how to handle this smoothly, grrr!
leppie
+2  A: 

I would benchmark it for your specific case.

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