Any sense to set obj = null(Nothing) in Dispose()?

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 (a Bitmap in 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; IDisposable is a handy “almost-kill” switch – why not detach everything available?
  • more importantly, I can cheekily now use this field to check (in methods etc) for disposal, throwing an ObjectDisposedException if it is null

Leave a Comment

tech