Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
microsoft.public.dotnet.framework.remoting
Remoting, AppDomains and Events
Aaron
9/7/2004 3:31:00 AM
Hi,
I have developed a framework, using AppDomains, to allow other developmers
to add plug-in's to our master application. I have written an application
manager class that hides the implementation specifics of this. Recently I
noticed the handle count of the application to climb as the application
loaded and unloaded plug-in's. Extensive trial and error has lead me to blame
the events. If I subscribe to the event(s) of a plug-in, which resides in
another appdomain, the Application manager class is never garbage collected.
Failing to subscribe measn that this class is cleaned up and all its held
resources freed. The handle count rising is a consequence of this as when
using events these mutex's are never destroyed.
Rather than take my word for all this (I'm terrible at explaining this
anyways), I have written a small console application to demonstrate what is
going on and this can be found at:
http://home.netspeed.com.au/aaronthomas/Remoting...
Code synopsis:
- The entry point to the application is found in RemotingEvents.cs
- There is a flag indicating the use of events in the main method called
"UseEvents"
- ApplicationManager.cs has the application manager implementation
Free hi-5 to anyone that gets this one, and a big thanks to anyone that
looks :)
Aaron.
1 Answer
Ken Kolda
9/7/2004 3:38:00 PM
0
Your leak is coming from the fact that your ApplicationManager class derives
from RemotableObject, which has overriden the InitializeLifetimeServices()
method to return null. As a result, when your ApplicationManager class gets
remoted (which occurs when you subscribe to the Application's events since
the Application object lives in a different AppDomain), the remoting
framework will NEVER release this reference, thus the object is never
eligible for GC.
The easiest way to fix this in your code is to add a call to
RemotingServices.Disconnect(this);
in your StopApplication() method.
Also, instead of using Mutex's, you might just want to use the lock()
statement -- I didn't see any inherent reason why a Mutex was needed instead
of simply using lock(). I believe lock() is much more lightweight since it's
a .NET CLR thing instead of an operating system functionality, so that may
also help avoid the handle leak.
Ken
"Aaron" <Aaron@discussions.microsoft.com> wrote in message
news:1962AF62-542D-4951-BFA1-00A9DBC4D471@microsoft.com...
> Hi,
>
> I have developed a framework, using AppDomains, to allow other developmers
> to add plug-in's to our master application. I have written an application
> manager class that hides the implementation specifics of this. Recently I
> noticed the handle count of the application to climb as the application
> loaded and unloaded plug-in's. Extensive trial and error has lead me to
blame
> the events. If I subscribe to the event(s) of a plug-in, which resides in
> another appdomain, the Application manager class is never garbage
collected.
> Failing to subscribe measn that this class is cleaned up and all its held
> resources freed. The handle count rising is a consequence of this as when
> using events these mutex's are never destroyed.
>
> Rather than take my word for all this (I'm terrible at explaining this
> anyways), I have written a small console application to demonstrate what
is
> going on and this can be found at:
>
>
http://home.netspeed.com.au/aaronthomas/Remoting...
>
> Code synopsis:
>
> - The entry point to the application is found in RemotingEvents.cs
> - There is a flag indicating the use of events in the main method called
> "UseEvents"
> - ApplicationManager.cs has the application manager implementation
>
> Free hi-5 to anyone that gets this one, and a big thanks to anyone that
> looks :)
>
> Aaron.
>
>
>
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Remoting, AppDomains and Events
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password