元编程 [英] Metaprogramming
问题描述
如果你在C#中进行元编程,生成的代码是垃圾收集还是
是否会无限期泄漏?
-
飞行青蛙顾问Jon D Harrop博士
http://www.ffconsultancy.com/products/?u
推荐答案
Jon Harrop写道:
Jon Harrop wrote:
>
如果你在C#中进行元编程,生成的代码是垃圾收集
还是无限期泄漏?
>
If you do metaprogramming in C#, is the generated code garbage collected
or does it leak indefinitely?
你能举个例子吗?
问候,
Mads
-
Med venlig hilsen / Regards
Systemudvikler / Systemsdeveloper cand.scient.dat,Ph.d 。,Mads Bondo
Dydensborg
Dansk BiblioteksCenter A / S,Tempovej 7-11,2750 Ballerup,Tlf。 +45 44 86 77
34
Can you give an example?
Regards,
Mads
--
Med venlig hilsen/Regards
Systemudvikler/Systemsdeveloper cand.scient.dat, Ph.d., Mads Bondo
Dydensborg
Dansk BiblioteksCenter A/S, Tempovej 7-11, 2750 Ballerup, Tlf. +45 44 86 77
34
无论他们如何成为(Reflection.Emit等),动态
组件的处理方式与常规组件相同;没有
从活动appdomain卸载程序集的好方法。你可以,然后将它加载到第二个应用程序域,然后杀死app-
域。一个很好的选择是(例如)使用静态缓存,这样你就可以反复创建相同的代码,但只需重复使用
你之前发出的程序集。
执行代码被视为正常;将使用相同的规则收集实例(或
)。
Marc
Regardless of how they come to be (Reflection.Emit, etc), dynamic
assemblies are treated the same as regular assemblies; there is no
good way to unload an assembly from an active appdomain. You can,
however, load it into a second app-domain and then kill the app-
domain. A good bet is to (for instance) use a static cache so that you
don''t end up creating the same code over and over, but simply re-use
the assembly you emitted earlier.
Executing code is treated as normal; instances will be collected (or
not) using the same rules.
Marc
On Thu,2007年10月4日06:04:01 +0100,Jon Harrop写道:
On Thu, 04 Oct 2007 06:04:01 +0100, Jon Harrop wrote:
如果你在C#中进行元编程,是否收集了生成的代码垃圾
或无限期泄漏?
If you do metaprogramming in C#, is the generated code garbage collected
or does it leak indefinitely?
如果没有提供更多详细信息,我发现很难确定你真正想要的是什么。
。
如果你动态创建和加载程序集,你应该将它们加载到一个新的appdomain中。你不能卸载一个程序集,但是你可以丢弃一个appdomain,然后丢弃appdomain将丢弃加载到它中的所有
程序集。
>
Ben
Without providing more detail, I find it difficult to be sure what you''re
really trying to do.
If you dynamically create and load assemblies, you should probably load
them into a new appdomain. You cannot unload an assembly, but you can
discard an appdomain and discarding the appdomain will discard all the
assemblies loaded into it with it.
Ben
这篇关于元编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!