<p>Say we have the following method:</p>

<pre><code>private MyObject foo = new MyObject();

// and later in the class

public void PotentialMemoryLeaker(){
  int firedCount = 0;
  foo.AnEvent += (o,e) =&gt; { firedCount++;Console.Write(firedCount);};
  foo.MethodThatFiresAnEvent();
}
</code></pre>

<p>If the class with this method is instantiated and the <code>PotentialMemoryLeaker</code> method is called multiple times, do we leak memory?</p>

<p>Is there any way to unhook that lambda event handler after we're done calling <code>MethodThatFiresAnEvent</code>?  </p>

Yes, save it to a variable and unhook it.
```
```
DelegateType evt = (o, e) => { firedCount++; Console.Write(firedCount); };
foo.AnEvent += evt;
foo.MethodThatFiresAnEvent();
foo.AnEvent -= evt;
```
```
And yes, if you don't, you'll
leak
memory, as you'll hook up a new delegate object each time. You'll also notice this because each time you call this method, it'll dump to the console an increasing number of lines (not just an increasing number, but for one call to MethodThatFiresAnEvent it'll dump any number of items, once for each hooked up anonymous method).