Overriding the finalize

  • Thread starter Thread starter Brian H
  • Start date Start date
B

Brian H

Hi gurus,

I have some cleanup code to ensure some unmanaged resources are released
when the app is closed. I thought overriding the finalize call, then
disposing of my objects, then calling mybase.finalize would do it, but this
never seems to get called. I'm closing the main form with a me.close()
call.

What's the best way to do this?

Thanks,
Brian
 
For my classes I've been using a standard technique described in the MSDN
docs:

~MyClass()
{
this.Dispose();
}

//implement IDisposable
public void Dispose()
{
//Deallocate native resources
DeleteDC(hDC);

GC.SuppressFinalize(this);
}
 
Yep -- that's probably a better place. I probably implemented it that way
based on a code snippet using Finalize, but now that you mention it, your
idea seems better :)

-Brian
 
Back
Top