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);
}
 
Brian:

Why not just do it in your class's Dispose method?
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top