防爆pression< TDelegate> .Compile和垃圾收集 [英] Expression<TDelegate>.Compile and Garbage Collection

查看:118
本文介绍了防爆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编译成一个<一个href="http://msdn.microsoft.com/en-us/library/system.reflection.emit.dynamicmethod.aspx">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&GT; .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:

<一个href="http://dlr.$c$cplex.com/SourceControl/changeset/view/54115#990638">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树都没有收藏价值的情况下,当你使用<一个href="http://msdn.microsoft.com/en-us/library/dd728224.aspx">Ex$p$pssion<T>CompileToMethod,那你这是没有用的<一个创建的AssemblyBuilder传递MethodBuilder href="http://msdn.microsoft.com/en-us/library/system.reflection.emit.assemblybuilderaccess.aspx">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.

这篇关于防爆pression&LT; TDelegate&GT; .Compile和垃圾收集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆