Useless destructor (finalizer)

May 12, 2010 at 10:43 AM

I found a destructor in the markup extension, which looks like this:

~ResExtension() { LocalizationSettings.Current.CultureChanged -= UpdateTarget; }

Here are my concerns:

  1. A destructor (finalizer) must only release unmanaged resources. 
  2. The destructor in the sample will never get called when it needs to really unsubscribe the event handler. Because you subscribe to event of the LocalizationSettings.Current object, it holds a refernce to the ResExtension object, making in unavailable for GC until you unsubscribe the event.  And this, in turn, means, that the destructor will never get called.

This code should have been placed in a Dispose method instead.