Garbage objects crossing the border of the AppDomain

When you pass an object that inherits from MarshalByRefObject to another AppDomain, there will be no GC.Collect () called by the AppDomain that created it, collects the object, provided that the object is not embedded in the AppDomain by the time GC.Collect () is called?

[When I say that I am not rooted, I mean that the developer did not get access to it.]

It seems that the object is not going to gather, but gets promoted to the next generation!

But if I stop passing the object to diff on AppDomain, it will be built as expected.

Is this design behavior? If so justified?

Thanks guys,

PS I know that GC.Collect () inside the code is bad for many reasons, I'm just trying to figure out how the GC will go on MBRO.

+4
source share
1 answer

As you mentioned, MBRO objects are hard to track for gc. Thus, MS implemented its behavior a little differently.
These objects have two properties: their initial lifetime (I think five minutes) and RenewOnCallTime (two minutes). If an MBRO is created, it has an initial lifetime. As soon as this time is zero, it is noted for gc.
Each call to an object allows the object to live longer for RenewOnCallTime (if the remaining lifetime is less than RenewOnCallTime).

Example (5 minutes of initial lifespan, 2 minutes of RenewOnCallTime):
Object created: the service life is five minutes; 4 minutes pass; The service life is one minute; Object call; The service life is two minutes; 2 minutes pass
Object tagged for gc, No Lifetime left;

Somewhere on MSDN there is a wonderful article about this (which I cannot find right now: /)

+2
source

All Articles