是否有解决办法的ToolStrip不内存泄漏 [英] Is there a workaround for ToolStrip to not leak memory
问题描述
我有一个简单的表格(MainForm中)打开另一种形式(子窗体),其中有一个ToolStrip的就可以了。
I have a simple form (MainForm) that opens another form (SubForm) which has a ToolStrip on it.
没有什么别的被叫形式。调用形式只有一个按钮。
There is nothing else on the called form. The calling form only has a button.
这被称为是永远不会回收,因为有一个事件处理程序的SystemEvents.User preferenceChanged形式的记忆。我看这是得到了修复.NET 3.5.1的问题。
The memory of the form that is called is never reclaimed because there is an eventhandler for SystemEvents.UserPreferenceChanged. I read that this is an issue that got fixed in .NET 3.5.1.
[修改应用程序上运行3.5.1或者让它不是真的固定或我做不同的事情]
[EDIT The application runs on 3.5.1 so either it is not realy fixed or I do something different]
我能做些什么,以便GC可以回收子窗体的记忆是什么?
Can I do something so that the GC can reclaim the memory of subform?
当我删除的ToolStrip,形式子窗体可以被垃圾再收集。
As soon as I remove the ToolStrip, the form subform can be garbage collected again.
的MainForm
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
SubForm subForm = new SubForm();
subForm.ShowDialog();
}
}
子窗体
public partial class SubForm : Form
{
public SubForm()
{
InitializeComponent();
}
}
实例保留图形与工具条
Instance Retention Graph with Toolstrip
推荐答案
您正在显示一个对话框,但从来没有处理它,所以至少把它放在一个用()子句,或以其他方式处置其在适当的时候。查看更多有关ShowDialog的这里
You're showing a dialog, but never disposing it, so at least put it in a using() clause , or otherwise dispose it when appropriate. See more about ShowDialog here
这篇关于是否有解决办法的ToolStrip不内存泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!