Weak references could have worked in this situation. Bear in mind that it's
only really an issue when your object is hooking onto an event in another
object which has a significantly longer life span. But it can be a really
nasty situation, especially if it's not you hooking up the event, but
something in the framework, and your object ends up being referenced through
a static hashtable or similar.
Niall
[quoted text, click to view] "Rahul Kumar" <rahul.kumar@sage.com> wrote in message
news:ueKpuWsUDHA.2192@TK2MSFTNGP09.phx.gbl...
> Hi David
>
> Thanks for the response. I have got few more questions for you:
>
> How to take care of the memory leaks in such cases?
> Are there in safeguards in .Net against it, except good programming
> practices?
> How about using WeakReferences to link the two Event objects?
>
> Regards
>
> Rahul
>
>
> "David Browne" <davidbaxterbrowne no potted meat@hotmail.com> wrote in
> message news:ekpBUdrUDHA.2192@TK2MSFTNGP09.phx.gbl...
> > "Rahul Kumar" <rahul.kumar@sage.com> wrote in message
> > news:%23xy$%23xoUDHA.580@TK2MSFTNGP09.phx.gbl...
> > > Hi all
> > >
> > > I have the following scenario in brief: There are two classes
> EventRaiser
> > > and EventConsumer. The EventRaiser raises an event and EventConsumer
> > listens
> > > to it, by adding its handler to the event chain of the EventRaiser's
> event
> > > delegate. My question is: If the EventConsumer goes out of context,
> > without
> > > removing itself from the event chain, does the EventRaiser still have
> its
> > > reference through the event chain?
> >
> > Yes
> >
> > >Will it not be garbage collected?
> >
> > It will not be garbage collected.
> >
> > David
> >
> >
>
>