防爆pression< TDelegate> .Compile和垃圾收集
当我编译EX pression为可执行code和获得委托 - ?请问code作为垃圾回收时,该委托的引用不再存在。
When I compile an expression into executable code and get the delegate - does the code get garbage collected when no more references to this delegate exist?
请问有任何文件?因为我没有找到任何东西在MSDN有用的。
Is there any documentation on this? Because I didn't find anything useful in the MSDN.
是的,code可以被垃圾收集。当你调用编译对T的前pression,在code编译成一个DynamicMethod,而那些有资格进行垃圾回收。
Yes, the code can be garbage collected. When you call Compile on an Expression of T, the code is compiled into a DynamicMethod, and those are eligible for garbage collection.
事实上,这在MSDN不是说明,但你可以看看的前pression&LT的执行情况; T> .Compile在DLR,这是.NET 4.0的船舶:
Indeed it's not indicated on the MSDN, but you can have a look at the implementation of Expression<T>.Compile in the DLR, which is what .net 4.0 ships:
http://dlr.$c$cplex.com/SourceControl/changeset/view/54115#990638
虽然编译器的执行是在.NET 3.5中不同的,仍在使用DynamicMethods(来源:我自己,我在单声道实现System.Linq.Ex pressions)
Although the implementation of the compiler was different in .net 3.5, DynamicMethods were still used (source: myself, I implemented System.Linq.Expressions in Mono).
在这里编译EX pression树都没有收藏价值的情况下,当你使用Ex$p$pssion<T>CompileToMethod,那你这是没有用的RunAndCollect标志。
The case where compiled expression trees are not collectible, is when you use Expression<T>CompileToMethod, and that you pass a MethodBuilder from an AssemblyBuilder which was not created with the RunAndCollect flag.