Does Holding A Delegate Reference Keep The Owning Object Alive?

I have a big question that can probably be best elucidated via some code:

public class SomeClass
{
    // This guy will raise an important event.
    private EventSource _source = new EventSource();

    public void AttachEventHandler()
    {
        // This guy will handle an important event...
    BigEventListener listener = new BigEventListener();
    _source.BigEvent += new EventHandler(listener.OnBigEvent);

    //What happens to listener instance here?
    //Will it be garbage collected?

    }
}

So what happens after the method AttachEventHandler() is called? I am assuming that the EventHandler delegate's reference to the OnBigEvent method of the listener instance is a hard reference. In other words,even though listener is a local instance and would normally go out of scope when AttachEventHandler ends, that the listener instance is not collected because of the delegate reference. Is this correct?

What others have said

Requesting Gravatar... Omer van Kloeten Jul 06, 2004 12:14 PM
# re: Does Holding A Delegate Reference Keep The Owning Object Alive?
These might be interesting:
http://weblogs.asp.net/greg_schechter/archive/2004/05/27/143605.aspx
http://www.interact-sw.co.uk/iangblog/2004/06/06/weakeventhandler
Requesting Gravatar... nospamplease75@yahoo.com (Haacked) Jul 06, 2004 1:11 PM
# RE: Does Holding A Delegate Reference Keep The Owning Object Alive?
Thanks Omar. So from these links, I can infer that my object will stay around (which in this case is my intended behavior).
Requesting Gravatar... Brad Wilson Jul 06, 2004 2:46 PM
# re: Does Holding A Delegate Reference Keep The Owning Object Alive?
Yes, delegates are a hard reference. Yes, your object will stay alive. In fact, this can cause of some circular reference memory leaks.
Requesting Gravatar... IanG on Tap Jul 07, 2004 8:46 AM
# Event Handlers, Circular References, and Alleged Memory Leaks

What do you have to say?

(will show your gravatar)
Please add 5 and 2 and type the answer here: