I create a window like this:
if (someCondition)
{
MyWindow wnd = new MyWindow();
wnd.Owner = this;
wnd.ShowDialog();
}
I want MyWindow’s destructor to be called at the closing curly bracket, but it doesn’t. Do I need to call something like delete/destroy for MyWindow’s destructor to be called?
The “destructor” or finalizer as it is called in C# is called whenever the Garbage Collector feels like. You can trigger the Garbage Collector manually using System.GC.Collect(), but you probably don’t want to do this. If your talking about Dispose() on the other hand you can make this being called by creating the window in a “using” clause:
This would make wnd.Dispose() be called when the using clause is done, and would basically be the same as writing:
About the usage of the IDisposable interface this question might be helpful – and several more on StackOverflow.