My class is using a COM resource, and I have inherited it from IDisposable. and for cleaning the unmanaged resources I have that Dispose() method where I am calling a Marshall.ReleaseCOMObject() method ...So my question is do we still need a Destructor method ( Finalizer) too ? to release the COM resources? When I DO have the finalzier method and calling Marshal or Dispose in it, I will get a RCW error and when I REMOVE the finalizer method I won't get RCW error anymore But if I look at a memory profiler I can see the Unmanaged Resources memory keeps getting increased eveery time I open the form that has this COM resources in it...so looks likes it is not cleaning it up? So what's the correct way of cleaning up COM resources in a C# app?
I will update the question with some code sample that I have soon.
Thanks.
private MyCOMobject theCOMobject = null;
static SuppressFieldCntrlr()
{
new SomeCalss();
}
private bool disposed = false;
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
private void Dispose(bool disposing)
{
if (!this.disposed)
{
if (disposing)
{
//nothing in here, is it just for Managed Resources?
}
Marshal.ReleaseComObject(this);
MethodFoo(false);
disposed = true;
}
}