How about the code below? implementing IDisposable in your form and removing all event handlers. However, is Microsoft already doing this on Close ()?
Does the GC.Collect Reference Help?
Some links and related posts:
What is the correct way to recycle a WPF window?
What is the correct way to recycle a WPF window?
/// <summary> /// Interaction logic for MyForm.xaml /// </summary> public partial class MyForm: IDisposable { public MyForm() {} private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) { Dispose(); } public void Dispose() { try{ _resourcescollection.Clear(); _resourcescoll = null; //close other resources } catch(exception ex) {} EventHelper.RemoveAllEventHandlers(_resources); EventHelper.RemoveAllEventHandlers(_timer); EventHelper.RemoveAllEventHandlers(_etc); EventHelper.RemoveAllEventHandlers(this); } ~MyForm() { Dispose(); } }
source share