title: How to create a Weak Referenced Event Handler?
body: <p>I am doing research on how to properly create a weak referenced event handler. Since WPF has already a solution for avoiding memory leaks with events, I decompiled the "WeakEventManager" class and spent some time on analysing it.</p>
  
  <p>As I found out, the "WeakEventManager" class relies on creating and storing a weak reference to the target object as well as to the event handler delegate. Here are some code segments:</p>
  
  <pre><code>this._list.Add(new WeakEventManager.Listener(target, handler));
  
  
    public Listener(object target, Delegate handler)
    {
         this._target = new WeakReference(target);
         this._handler = new WeakReference((object) handler);
    }
  </code></pre>
  
  <p>I am asking myself if this simple solution would already be working or did I overlook an important aspect, since most other solutions I found on the Internet are complex and hard to understand. The best solution I could find so far
  uses an unbound delegate. That is some kind of wrapper delegate that takes the event handler and event subscriber instance as a parameter (yes, it requires the event subscriber object to be passed in during delegate invocation).</p>
  
  <p>You can find this great article here:</p>
  
  <p><a href="http://diditwith.net/CommentView,guid,aacdb8ae-7baa-4423-a953-c18c1c7940ab.aspx#commentstart" rel="nofollow">http://diditwith.net/CommentView,guid,aacdb8ae-7baa-4423-a953-c18c1c7940ab.aspx#commentstart</a></p>
  
  <p>The "WeakEventManager" class doesnt't rely on knowing the subscriber class or any additional information. Beyond that it also works with anonymous delegates. Why do developers spent so much time on writing a solution that is not only working but also convenient to use, if a solution only requires them to store a weak reference to the delegate? What's the catch?</p>
  
  <p><strong>Update</strong>: Because someone downvoted this question (may be it is a little bit unspecific), I want to give a more precise question: </p>
  
  <p>Is that source code above all it takes to create a working weak event handler? If not, what is missing?</p>