Why does WPF not use IDisposable, and what are the ramifications?

谁都会走 提交于 2019-12-11 19:52:42

问题


So, I've never done a sizable WPF project before now, but this one has me wondering; What's up with WPF classes not implementing IDisposable? By comparison, all of the UI elements in Windows Forms implement IDisposable, to assure they get rid of the underlying handles and such.

I think the same Windows objects are under the covers there, and those resources have to be released; so, how is WPF doing that?

Is there anything I need to be doing with my WPF Window objects beyond Close()ing them?


回答1:


WinForms controls have handles because they are wrappers around Win32 controls. WPF controls are not (well, windows are, but the controls they host are not). The reason is that, after all, a WPF window is just a Direct3D rendering context, and all controls are just a bunch of triangles. So, they don't need to be actually registered to the OS, and therefore, they don't have handles (except windows and anything that inherits from HwndHost, of course, which are Win32 objects).

That's why there's such a sizeable interop layer between WPF and WinForms: WPF controls simply aren't Windows objects.



来源:https://stackoverflow.com/questions/10583810/why-does-wpf-not-use-idisposable-and-what-are-the-ramifications

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!