Still need separate AppDomains for dynamic compilation?
-
2011年11月14日 5:46
I have just started playing around with the Roslyn CTP, and noticed that when a scripting session is created and dynamic code executed, that a new dynamic assembly becomes referenced by the current AppDomain. This can be seen by looking at AppDomain.CurrentDomain.GetAssemblies() both before and after the scripting engine executes.
Does this mean that for a program that is constantly doing dynamic compilation over and over again, we will still need to create new AppDomains to execute the scripting engine in to avoid memory leaks?
What are the long term plans around this for Roslyn?
すべての返信
-
2011年11月14日 12:25
From what I observed, each instance of ScriptEngine creates its own collectible assembly. What that means is that if your application doesn't hold any references to types defined in that assembly, it's eligible for garbage collection.
So, to avoid memory leaks, you don't have to create new AppDomains. But you (probably) have to create new ScriptEngines.
But this appears to apply only when you don't use sessions. If you do, the created assembly is not collectible. That would mean that if you need to use sessions, you still need to create new AppDomains to avoid leaks. Of course, this could change before the final release.
- 編集済み svick 2011年11月14日 12:37 added info about sessions
- 編集済み svick 2011年11月14日 12:37 missing space
- 回答の候補に設定 Tomas MatousekMicrosoft Employee, Editor 2011年11月14日 22:45
- 回答としてマーク Karen Ng MSFTOwner 2011年11月17日 8:03
-
2011年11月14日 22:45回答者:
That's correct. Another case when an uncollectible code is emitted is when we hit a limitation of Reflection.Emit or collectible assemblies (http://msdn.microsoft.com/en-us/library/dd554932.aspx).
We are definitely aware of these problems and are working towards improving collectibility and memory overhead of code generated by Roslyn. The current design certainly isn't final.
- 回答の候補に設定 Tomas MatousekMicrosoft Employee, Editor 2011年11月14日 22:45
- 回答としてマーク Karen Ng MSFTOwner 2011年11月17日 8:03

