gpt4 book ai didi

Silverlight ChildWindow 内存泄漏

转载 作者:行者123 更新时间:2023-12-04 02:51:18 25 4
gpt4 key购买 nike

有谁知道如何使用 ChildWindow 解决 SL3 中的内存泄漏?

引用下面的代码片段:

 private void Button_Click(object sender, RoutedEventArgs e)
{
var window = new ChildWindow();

window.Closed += new EventHandler(window_Closed);

window.Show();
}

void window_Closed(object sender, EventArgs e)
{
((ChildWindow)sender).Closed -= new EventHandler(window_Closed);

WeakReference reference = new WeakReference(sender);

GC.Collect();

GC.WaitForPendingFinalizers();

bool isControlAlive = a.IsAlive;
}

它始终显示为仍然“事件” - 当我在任务管理器中监视 iexplore 实例时 - 每次打开和关闭子窗口时内存都会继续增加。

请帮忙。

谢谢。

克里斯

最佳答案

据我所知,目前还没有官方修复。 This page描述内存泄漏的性质:

...[ChildWindow] subscribes to the RootVisual_GotFocus multiple times, but it only unsubscribes it once during close. This causes the ChildWindow to permanently stay in memory attached to the GotFocus event of the RootVisual.

根据评论部分,您可以按如下方式修改 Silverlight Toolkit 代码以解决问题:

Modify the ChildWindow_LostFocus function on ChildWindow.cs (Line 731) to subtract the RootVisual_GotFocus listener before adding again:

Application.Current.RootVisual.GotFocus -= this.RootVisual_GotFocus;
Application.Current.RootVisual.GotFocus += this.RootVisual_GotFocus;

关于Silverlight ChildWindow 内存泄漏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2851951/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com