Do I need to "release" a reference to an object living in a different app-domain.

  • Thread starter Thread starter Peter Strøiman
  • Start date Start date
P

Peter Strøiman

Hi.

I have a component that needs to run in its own execution environment and
with its own configuration file.

Therefore I create a new AppDomain at runtime. Let's say that my component
exists in "a.dll"

there I have

public class MyClass : MarshalByRefObject
{
public void test();
}

When I create my component, I write

AppDomain newDomain = AppDomain.Create( ... );
MyClass newObject = (MyClass)newDomain.CreateInstanceFromAndUnwrap( "a.dll",
"MyClass" )
newObject.test();

This all works perfectly fine.

My question is - now that I create an object that is a proxy for an object
in a different AppDomain, do I need to do anything special to clean up after
using the object.

Thanks in advance,
Pete
 
Peter Strøiman said:
Hi.

I have a component that needs to run in its own execution environment and
with its own configuration file.

Therefore I create a new AppDomain at runtime. Let's say that my component
exists in "a.dll"

there I have

public class MyClass : MarshalByRefObject
{
public void test();
}

When I create my component, I write

AppDomain newDomain = AppDomain.Create( ... );
MyClass newObject = (MyClass)newDomain.CreateInstanceFromAndUnwrap( "a.dll",
"MyClass" )
newObject.test();

This all works perfectly fine.

My question is - now that I create an object that is a proxy for an object
in a different AppDomain, do I need to do anything special to clean up after
using the object.

No. Remember there is only one managed heap per process. When your proxy
becomes unreachable, the remote object will be unreachable and will be
collected. But the other AppDomain will not shut itself down.

David
 
Back
Top