Alex Rivera | Logout

Destructors are not guaranteed to be called

Asked 2011-07-14T11:43:15.377
10

I came across the following quote "Desctructors are not guaranteed to be called." and this scares me a bit.

It goes on to say that even a try finally block can be interrupted, causing memory leaks. It does give a solution by either placing your code in CER (constrained execution region) or derive from the CriticalFinalizerObject.

My question is

  1. What are the tradoffs by using CriticalFinalizerObject, if any?
  2. Are their any cases were you found deriving from CriticalFinalizerObject was really usefull?
  3. Should I only worry about using this when I start running into Memory leaks?
Edit
Report

1 Answer

0

I would suggest using the IDisposable interface for all resources that need to be destroyed, and use them in a using block.

answered 2011-07-14T11:48:42.523

Your Answer