views:

36

answers:

1

The problem is the following. There is an application that is at work creating additional AppDomain's and loads there assembly (custom user scripts). In the main application, there are some objects, references to which to transfer ownership to those created AppDomain's. Objects themselves are the MarshalByRefObject, and they are disabled lifetimeservices (InitializeLifetimeService returns null).

All of this works. However, these AppDomain's are created and destroyed... with the destruction caused by Unload the domain, and references to created objects - are forgotten.

In general, as a result of gradual memory ends, because these "forgotten" objects do not seem freed, although they have no links anywhere, and AppDomain, which were links - has long been unloaded...

Hence the question - where the bug? What's wrong? Why not exempt facilities after unloading domain?

No one thought - to take into account their own links to these objects for each domain loaded, and after his unloaded - cause for each object RemotingServices.Disconnect (...). It may well have to do when lifetime-service is not available?

+1  A: 

I'd make the following changes:

Implement IDisposable and ISponsor for these types. Override these types' InitializeLifetimeService method and, instead of returning null, make each instance its own sponsor.

These types should return a positive TimeSpan from Renewal until they are disposed. Just make sure to dispose of them before destroying the appdomain.

Will