Nederlandstalig? U woont in Vlaanderen? Bezoek en kom in contact met de beste handelaars in je buurt

Disposing of the IDisposable implementation

Everytime I need to implement the IDisposable interface I have to lookup the recommended way of doing so. That in itself is a bad sign, so I figured I might as well get rid of this by putting the implementation in a reusable base class, based on the officially recommended way:

So now I can simply inherit from Disposable, and I just need to implement the two abstract methods. Here's a made up example to illustrate this:

Obviously, you can't use the Disposable base class if you're already inheriting from another base class so in that case you'd still have to implement the IDisposable interface.

Update: Here's a thread-safe version of this idea.

Written by Davy Brion, published on 2008-06-17 15:01:36
Categories: memory-management , patterns , performance

« Are women better developers than men? How To Write Testable ASP.NET WebForms »

comments powered by Disqus