How to properly dispose of an object

Posted by VoodooChild on Stack Overflow See other posts from Stack Overflow or by VoodooChild
Published on 2010-06-11T20:38:42Z Indexed on 2010/06/11 20:42 UTC
Read the original article Hit count: 175

Hi Guys,

I am experiencing something weird and have a workaround already, but I don't think I understood it well.

If I call the Method below numerous times within a class:

public void Method()
{
 Foo a = new Foo();

 a.Delegate1Handler = ViewSomething();
}

So I am reinitializing "a" every time but for some reason a.Delegate1Handler is still around from the previous initialization, and therefore ViewSomething() is called again and again and again....

I feel like I am forgetting something critical here?

Foo's guts look like:

public delegate void Delegate1(T t);
public Delegate1 Delegate1Handler { get; set; }

© Stack Overflow or respective owner

Related posts about c#

Related posts about design-patterns