内存泄漏:Close()不处理窗口 [英] Memory Leak: Close() doesn't dispose Window

查看:371
本文介绍了内存泄漏:Close()不处理窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在WPF应用程序中发现了内存泄漏.我跟踪到一个实例化并随后(以编程方式关闭)的窗口.但是,如果我分析内存(使用.NET Memory Profiler),则会看到以下错误:

未处理的实例:MS.Win32 HwndSubclass

HwndSubclass似乎是Window内部的东西.不幸的是,窗户不是一次性的.因此,我只在最后调用Close()(甚至将其设置为null).但是,内存不会释放(我的内存中的所有内容也都不会释放). 窗口)...

HwndSubclass seems like something internal to Window. Unfortunately Window is not disposable. Therefore I just call Close() at the end (and even set it to null). Nonetheless, memory is not freed (and so is all the stuff contained by my Window)...

推荐答案

让我添加到目前为止我尝试过的一些东西:

Let me add some stuff I tried so far:

-在局部变量而不是成员上使用Window

- use Window on a local variable instead of a member

-使用SendMessage(hWnd,WM_CLOSE,IntPtr.Zero,IntPtr.Zero)代替Close()

- use SendMessage(hWnd, WM_CLOSE, IntPtr.Zero, IntPtr.Zero) instead of Close()

-关闭前删除现有的事件处理程序

- remove existing event handler before closing


这篇关于内存泄漏:Close()不处理窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆