Re: Events unsubscribing and resource leaks?



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?



.



Relevant Pages

  • RE: Calling bash things inside perl script.
    ... To unsubscribe, e-mail: beginners-unsubscribe@xxxxxxxx For additional ... commands, e-mail: beginners-help@xxxxxxxx http://learn.perl.org/ ... This e-mail may contain confidential information. ... Any opinion expressed in this e-mail is personal to the sender ...
    (perl.beginners)
  • Re: lists.debian.org vs google groups
    ... This results in the sender being unable to find the destination, ... They must edit every messges they want to respond... ... To UNSUBSCRIBE, email to debian-user-REQUEST@xxxxxxxxxxxxxxxx with a subject of "unsubscribe". ...
    (Debian-User)
  • Re: Sex spam again on the list
    ... zen.spamhaus.org combined blocklist wich is very effective and has ... no false positives. ... to the sender. ... To UNSUBSCRIBE, email to debian-user-REQUEST@xxxxxxxxxxxxxxxx ...
    (Debian-User)
  • [OT] Re: Poster to this lists email address not obfuscated?
    ... sender address by the spammers? ... I only care about gumming up their list of potential *recipient ... When spammers start sending mail to non-existent ... To UNSUBSCRIBE, email to debian-user-REQUEST@xxxxxxxxxxxxxxxx ...
    (Debian-User)
  • Events unsubscribing and resource leaks?
    ... You need to also unsubscribe it to avoid a resource leak so that the object ... but when you use visual studio to create events for objects ...
    (microsoft.public.dotnet.languages.csharp)