ToolStrip内存泄漏 [英] ToolStrip memory leak

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

问题描述

我在使用SWF-ToolStrip处理内存泄漏时遇到了麻烦. 根据此 http://connect.microsoft.com/VisualStudio/feedback/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天全站免登陆