垃圾收集对象跨越边界的AppDomain [英] Garbage collecting objects crossing AppDomain boundary

查看:185
本文介绍了垃圾收集对象跨越边界的AppDomain的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在传递自MarshalByRefObject继承到一个不同的AppDomain的对象,不会GC.Collect的()由创建它收集对象的AppDomain诱导,提供该对象不是由时间GC根植于任何的AppDomain .Collect()叫什么名字?

When you pass an object that inherits from MarshalByRefObject to a different AppDomain, won't GC.Collect() induced by the AppDomain that created it collect the object, provided that the object is not rooted in either AppDomain by the time GC.Collect() called?

[我说的不是源于我的意思是没有任何开发者编写的代码访问它了。]

[When I say not rooted I mean no developer written code access it anymore.]

看来,对象没有被收集而是获得晋升到下一代!

It appears that the object is not getting collected but rather getting promoted to the next generation!

但是,如果我停止传递对象到差异的AppDomain,它是如预期得到收集。

But if I stop passing the object to a diff AppDomain, it is getting collected as expected.

这种行为是设计?如果是这样的道理呢?

Is this behavior by design? If so rationale?

谢谢你们,

P.S。我知道,所以GC.Collect()内的代码是坏的原因有很多,我只是想了解GC将如何采取MBROs的地方。

P.S. I know GC.Collect() within code is bad for many reasons, I'm just trying to understand how GC would take place on MBROs.

推荐答案

正如你所提到MBRO对象是很难跟踪的GC。因此,MS实现自己的行为有点不同的结果
那些对象有两个属性:他们最初的一生(我认为5分钟)和RenewOnCallTime(两分钟)。如果MBRO对象被创建它有它的初始寿命。一旦这个时间为零它被标记为GC。结果
的对象每次调用允许对象住RenewOnCallTime更长(如果剩余寿命小于则RenewOnCallTime)。

As you mentioned MBRO objects are hard to keep track of for the gc. So MS implemented their behaviour a bit different.
Those objects have two properties: Their initial lifetime (I think five minutes) and a RenewOnCallTime (two minutes). If a MBRO object is created it has it's initial lifetime. Once this time is zero it is marked for gc.
Every call on the object allows the object to live for RenewOnCallTime longer (if the remaining lifetime is less then the RenewOnCallTime).

有关的例子(5分钟初始寿命,2分RenewOnCallTime):创建结果
对象:寿命为五分钟,结果
4分及格;一生为一分钟,结果
呼叫对象提出的;寿命是两分钟,结果
2分钟一趟,结果
对象标记为GC,没有留下终身;

For an example (5 minutes initial lifetime, 2 minutes RenewOnCallTime):
Object is created: Lifetime is five minutes;
4 minutes pass; Lifetime is one minute;
Call to object is made; Lifetime is two minutes;
2 minutes pass;
Object is marked for gc, No Lifetime left;

某处MSDN上有这个一个伟大的文章(我现在无法找到:/)

Somewhere on MSDN there is a great article about this (which I can't find right now :/)

这篇关于垃圾收集对象跨越边界的AppDomain的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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