如何将列表项设置为null C#?

Emb*_*rja 4 c# dispose memory-leaks

我有一个名为container的用户控件,我在运行时添加其他用户控件.

我想从容器中删除所有控件,我正在做container.Controls.Clear()但我的控件仍然在内存中,我怎样才能使它们为空?

eri*_*osg 8

调用Clear方法不会从内存中删除控制句柄.您必须显式调用Dispose方法以避免内存泄漏.

阅读更多:http://msdn.microsoft.com/en-us/library/system.windows.forms.control.controlcollection.clear.aspx