WeakReference and event handling


Question

Is it a good practice to implement event handling through WeakReference if that event is the only thing holding the reference and that we would need the object to be garbage collected?

As an argument to this:

Folks say that if you subscribe to something it’s your responsibility to unsubscribe and you should do it.

1
31
10/17/2012 9:44:06 PM

It is good to get in the habit of unsubscribing from events when you can, but sometimes there isn't an obvious "cleanup" method where it can be done. We recently posted a blog article on this subject; it includes methods that make it easy to subscribe to an event with a WeakReference.

14
10/9/2008 3:59:52 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon