我有mfc ++项目,当我在c#COM dll中关闭用户控件时。内存没有减少,当我再次打开时内存会增加更多。
那么如何处置我的用户控件?这是我的处置方法
public partial class UserControl1 : UserControl,IDisposable
{
private IntPtr handle;
private Component component = new Component();
private bool disposed = false;
public UserControl1(IntPtr handle)
{
this.handle = handle;
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
if (!this.disposed)
{
if (disposing)
{
component.Dispose();
}
CloseHandle(handle);
handle = IntPtr.Zero;
disposed = true;
}
}
~UserControl1()
{
GC.Collect();
Dispose(false);
}
}