Re: Events unsubscribing and resource leaks?
- From: "Christof Nordiek" <cn@xxxxxxxxx>
- Date: Thu, 28 Sep 2006 09:29:30 +0200
Hi Daniel,
see inline.
"Daniel" <DanielV@xxxxxxxxxxxxxxxx> schrieb im Newsbeitrag
news:u74hSwp4GHA.2348@xxxxxxxxxxxxxxxxxxxxxxx
Hey guys
When you hook an event (c# 2.0 syntax): myEvent += MyMethodToFire;
You need to also unsubscribe it to avoid a resource leak so that the
object it is in gets garbage collected like so : myEvent -=
MyMethodToFire;
Are you sure?
The event will prevent the reciever of the event (if the method is an
instance method) to be collected, not the sender. If the sende is the
reciever, this also wouldn't prevent the instance from being collected. So
where is the resource leak?
The event should only be unsubscribed, if the reciever shall ciece to
recieve the event while the sender remains to exist (and fireing the event).
That's all fine, but when you use visual studio to create events for
objects it never creates an unsubscribing reference, so is it puting in
resource leaks? Or is this being cleared somewhere that i am not seeing?
Since the sender will be contained by the sender, i don't think this cuold
be a problem.
Also what is the best way to clean up a singleton class?
.
- Follow-Ups:
- Re: Events unsubscribing and resource leaks?
- From: Daniel
- Re: Events unsubscribing and resource leaks?
- References:
- Events unsubscribing and resource leaks?
- From: Daniel
- Events unsubscribing and resource leaks?
- Prev by Date: Re: Replacing XML Elements programmatically with either VB.Net or C#
- Next by Date: Re: Different Entry Point
- Previous by thread: Events unsubscribing and resource leaks?
- Next by thread: Re: Events unsubscribing and resource leaks?
- Index(es):
Relevant Pages
|