Do you need to remove an event handler in the destructor?

Viewed 34145

I use some UserControls which get created and destroyed within my application during runtime (by creating and closing subwindows with these controls inside).
It's a WPF UserControl and inherits from System.Windows.Controls.UserControl. There is no Dispose() method I could override.
PPMM is a Singleton with the same lifetime as my application.
Now in the constructor of my (WPF) UserControl, I add an event handler:

public MyControl()
{
    InitializeComponent();

    // hook up to an event
    PPMM.FactorChanged += new ppmmEventHandler(PPMM_FactorChanged);
}

I got used to removing such event handler in the destructor:

~MyControl()
{
    // hook off of the event
    PPMM.FactorChanged -= new ppmmEventHandler(PPMM_FactorChanged);
}

Today I stumbled upon this and wondered:

1) Is this neccessary? Or does the GC take care of it?

2) Does this even work? Or would I have to store the newly created ppmmEventHandler?

I'm looking forward to your answers.

9 Answers
Related