Personally I tend to; for two reasons:
- it means that if somebody has forgotten to release the
Foo(perhaps from an event) any downstream objects (aBitmapin this case) can still be collected (at some point in the future – whenever the GC feels like it); it is likely that this is just a shallow wrapper around an unmanaged resource, but every little helps.- I really don’t like accidentally keeping an entire object graph hanging around just because the user forgot to unhook one event;
IDisposableis a handy “almost-kill” switch – why not detach everything available?
- I really don’t like accidentally keeping an entire object graph hanging around just because the user forgot to unhook one event;
- more importantly, I can cheekily now use this field to check (in methods etc) for disposal, throwing an
ObjectDisposedExceptionif it isnull