问题描述
我替换了:
panel.Controls.Clear();
与:
清除(面板);
地点:
public static void Clear(Control ctrl){而 (ctrl.Controls.Count > 0) ctrl.Controls[0].Dispose();}
我收到以下错误:在 Application.Run(new Form1());
System.ObjectDisposedException 未处理无法访问已处置的对象.对象名称:'标签'.
知道为什么会这样吗?
谢谢.
请参阅如何在不导致内存泄漏的情况下清除()控件一个>
抱歉,我可能正在处理一些我只想从其父级中删除的内容.我会检查的.感谢您的回答.
解决方案我可能处理了一些 Control
我稍后在代码中使用的.>
I replaced:
panel.Controls.Clear();
with:
Clear(panel);
Where:
public static void Clear(Control ctrl)
{
while (ctrl.Controls.Count > 0) ctrl.Controls[0].Dispose();
}
And I get the following error: at Application.Run(new Form1());
System.ObjectDisposedException was unhandled
Cannot access a disposed object.
Object name: 'Label'.
Any idea why that might be?
Thanks.
EDIT: See How to Clear() controls without causing a memory leak
EDIT: Sorry, I’m probably disposing of something which I just want to remove from its parent. I’ll check that. Thanks for the answers.
解决方案I was probably disposing of some Control
s I was using later on in the code.
这篇关于尝试替换 Controls.Clear() 以避免内存泄漏不起作用 - 为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论