开发者

Silverlight ChildWindow Memory Leak

Does anyone know how to resolve to the memory leak in SL3 with the ChildWindow?

Refer to the code snippet below:

 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.WaitForPendingFin开发者_高级运维alizers();

        bool isControlAlive = a.IsAlive;
    }

It is always showing as still "alive" - and when I monitor the iexplore instance in Task Manager - the memory continues to increase everytime I open and close the Child Window.

Please help.

Thanks.

Chris


There is no official fix yet as far as I know. This page describes the nature of the memory leak:

...[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.

Per the comments section, you can modify the Silverlight Toolkit code as follows to fix the problem:

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;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜