ToolStrip 内存泄漏 [英] ToolStrip memory leak

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

问题描述

我在使用 SWF-ToolStrip 时遇到了内存泄漏问题.根据这个 http://connect.microsoft.com/VisualStudio/反馈/ViewFeedback.aspx?FeedbackID=115600# 已解决.但这里似乎没有.

I've been having trouble with memory leaks with the SWF-ToolStrip. According to this http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=115600# is has been resolved. But here it seemes not.

有人知道如何解决这个问题吗?

Anyone know how to resolve this?

推荐答案

这个问题似乎在 .NET 3.5 SP1 和 .NET 4.0 中仍然存在.

This problem seems to persist in .NET 3.5 SP1 as well as .NET 4.0.

要重现该问题,您必须创建一个 ToolStrip,其中的项目多于它可以显示的数量,这会导致它创建一个溢出按钮.只有当您实际单击溢出按钮时才会出现问题.单击它会导致创建一个 ToolStripOverflow 对象,该对象订阅 Microsoft.Win32.UserPreferenceChangedEventHandler 事件.ToolStrip 不会处理 ToolStripOverflow 对象,这会导致事件处理程序未被删除并导致泄漏.

To reproduce the problem you must create a ToolStrip with more items than it can display which causes it to create an overflow button. The problem only appears when you actually click the overflow button. Clicking it causes a ToolStripOverflow object to be created which subscribes to the Microsoft.Win32.UserPreferenceChangedEventHandler event. The ToolStrip doesn't dispose of the ToolStripOverflow object which causes the event handler to not be removed and causes a leak.

这给我们在创建带有 ToolStrips 的表单的大型应用程序中带来了巨大的问题.

This caused us massive problems in a large app that created forms with ToolStrips on them.

解决方法是更改​​承载 ToolStrip 的窗体或控件的 Dispose 方法,如下所示:

A work around is to change the Dispose method of the form or control that hosts the ToolStrip as follows:

protected override void Dispose(bool disposing)
{

    if (disposing)
    {
        var overflow = toolStrip1.OverflowButton.DropDown as ToolStripOverflow;
        if (overflow != null)
            overflow.Dispose();
    }


    if (disposing && (components != null))
    {
        components.Dispose();
    }
    base.Dispose(disposing);
}

这为我们解决了

这篇关于ToolStrip 内存泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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