When can I dispose an IDisposable WPF control e.g. WindowsFormsHost?

后端 未结 4 1107
情书的邮戳
情书的邮戳 2021-01-02 01:38

The WPF control WindowsFormsHost inherits from IDisposable.

If I have a complex WPF visual tree containing some of the above controls what event or method can I use

4条回答
  •  梦毁少年i
    2021-01-02 01:44

    WPF Controls don't implement the IDisposable interface, because they have nothing to dispose (No handles to clean up, no unmanaged memory to release). All you need to do is make sure that you don't have any references to the controls and the GC will clean them.

    Therefore WPF employs weak event patterns to ensure that controls can be garbage collected. This is the pattern you need to implement to ensure clean-up, not IDisposable.

提交回复
热议问题