object.close() or object = null?

  • Thread starter Thread starter Justin Rich
  • Start date Start date
It's true that finalization is different from disposal, and not even
guaranteed. But in the context of "the GC _ONLY_ finalizes an object" (my
emphasis, obviously), I have a problem with the statement. "ONLY
finalizing" implies that the GC is not disposing when it finalizes. But
assuming the finalizer was written correctly, IMHO that's the whole point:
for it to do the disposing that should have been done already.

In other words, the GC does implicitly wind up disposing, even though

The GC gives the object a chance to dispose itself... which I argue is
different than having the GC dispose it, especially from the perspective of
the person designing the object.
 
Jon Skeet said:
It's very rarely worth setting a variable to null. Most of the time you
don't gain anything - you just end up with more code which doesn't do
anything useful. There are a few exceptions, as Ben mentioned, but I'd
say I only manually "null out" a variable about once a month - if that!

I don't think I ever do. I sometimes call .Clear on a collection that's a
static member, such collections are usually marked readonly so they can't be
nulled anyway.

The important thing to know is that static members always provide
reachability.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top