Oddly enough, I always would... even though it perhaps should have been
done already; I find that the following default works well for
disposable items:
1: is it disposable?
2: do I feel ownership? (i.e. did I create / adopt it in this code
block)
3: is the scope contained? (i.e. it doesn't logically live beyound this
region, as non-modal forms would)
If I can answer "yes" to these, then I use "using", and this tends to
be the majority; so here I would:
using(SomeForm formInstance = new SomeForm()) {
// [*] note for later
formInstance.ShowDialog();
}
OK, in reality there isn't enough going on here that it is an issue,
but! Now imagine that there are a few lines of code at point [*]; now
it becomes less clear whether it is "clean" when abandoned through an
exception. It is /probably/ the case Dispose() mainly deals with
"hwnd"s, in which case they *probably* won't have even been issues
until .Show() / .ShowDialog(), but that is using inside knowledge of a
class, which defeats the purpose of the encapsualtion. Besides, I'm
sure I could create a Form class which calls CreateHandle() earlier
than normal, or obtains it's own disposable resources in the ctor.
The other advantage is this approach it works in all normal scenarios,
and saves you from having to ask "should I do x / y / z", which you can
only really answer by knowing too much about the internals of the class
in question. Which could change at any point. And yes, finalizers are
there to a point, but I always prefer deterministic disposal of
unmanaged resources.
Just a counterview...
Marc