CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

Grant Killian's Blog

No, this has nothing to do with beer -- but maybe it should?

More thoughts on Garbage Collection

Ever beat a dead horse?

Brent Rector of Wintellect discusses Finalizers, sharing how the GC process really behaves and why we should think twice thrice before using Finalizers.  Make sure your design warrants the extra overhead.

Other highlights from Brent's article include:

  • Despite some semantic parallels, C++ destructors behave very differently than C# destructors (and .Net destructors in general).
  • Using Finalizers can cause a significant performance penalty, especially when one considers the multi-step process (and threads) involved with Finalization.
  • If you must use a Finalizer, keep it as simple as possible.
  • His opinion is that since Java has finalizers, MSFT added finalizers to .Net to match up in a feature-by-feature comparison with Java
  • You can use the Dispose pattern if you want to achieve non-deterministic finalization (I discussed this here)

If you must use Finalizers in your design, keep them brief and free of exception-throwing code; use the Dispose()    pattern and document your classes so clients know to invoke the Dispose() method appropriately (or with a using statement in c#). 



Comments

Paul Laudeman (plaudeman@NOSPAMyahoo.com) said:

+1 on the book recommendation!

That book has excellent coverage of the internals of .NET and contains a wealth of information that you can put to practical use in architecting and building your applications.
# September 4, 2003 1:59 AM

Grant Killian said:

# January 23, 2004 9:22 AM

Leave a Comment

(required)  
(optional)
(required)  

Enter the numbers above:
Add
Check out Devlicio.us!