开发者

Interaction between multiple AppDomain. Problems with the destruction of singleton-objects

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 开发者_JAVA技巧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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜