title: Does an event handler keep the object alive?
body: <p>I have the following situation.</p>
  
  <p>A <code>List&lt;WeakReference&lt;MyClass&gt;&gt;</code>, <code>MyClass</code> has an event called <code>MyEvent</code>. I iterate over the list, and for every alive reference, I might invoke the <code>MyEvent</code> on it's target.</p>
  
  <p>In other parts of my code, I keep live references to these objects. Let's say the process looks something like this:</p>
  
  <pre><code>var list = new List&lt;WeakReference&lt;MyClass&gt;&gt;();
  var a = new MyClass();
  a.MyEvent += delegate {
      DoSomeStuff(a);
  };
  list.Add(new WeakReference&lt;MyClass&gt;(a));
  </code></pre>
  
  <p>Now let's say I have no further use of <code>a</code>, and decide to dispose of it. So now, <code>a = null</code>.</p>
  
  <p>I have a periodic checks setup that clear the original list of dead references. What I'm wondering is, will this event handler I have hooked up keep the former <code>a</code> instance of <code>MyClass</code> alive, and in turn prevent me to clean it up from the list?</p>
  
  <p>What if the event wasn't just a normal <code>Action</code>, but instead an <code>Action&lt;MyClass&gt;</code> that passed itself as the parameter to the handlers? In a way, that handler still has a reference to the original object, even though the handler might never get called.</p>
  
  <p>This might be really obvious and I can think of similar situations where I'd know the answer but the fact that I'm hooking that function on the very object makes me suspicious. If it does keep it alive it breaks my whole system so I need to know.</p>