views:

342

answers:

1

The thing is that WPF Window doesn't implement IDisposable interface which led me to believe, that I don't have to manually dispose of it when I open it by calling ShowDialog() but the first comment on this MSDN page states differently. Does anybody know what's the truth?

+2  A: 

Only if you open the window using Show() instead of ShowDialog().

From the documentation:

If a window, opened by calling ShowDialog, and with a Button with its IsCancel property set to true, will automatically close when the button is either clicked, or ESC is pressed. If the window was opened using Show, however, Close must be explicitly called, such as from Click event handler for the Button.

and:

Closing a window causes the Closing event to be raised. If the Closing event isn't canceled, the following occurs:

  • The Window is removed from Application.Windows (if an Application object exists).
  • The Window is removed from the owner Window if the owner/owned relationship was established before the owned Window was shown and after the owner Window was opened.
  • The Closed event is raised.
  • Unmanaged resources created by the Window are disposed.
  • If ShowDialog was called to show the Window, ShowDialog returns.
Andy Shellam