Может кто-нибудь объяснить, в чем смысл обнуление объекта до того, как он выйдет из области видимости?

I have seen code with the following logic in a few places:

public void func()
{
   _myDictonary["foo"] = null;
   _myDictionary.Remove("foo");
}

What is the point of setting foo to null in the dictionary before removing it?

I thought the garbage collection cares about the number of things pointing to whatever *foo originally was. If that's the case, wouldn't setting myDictonary["foo"] to null simply decrease the count by one? Wouldn't the same thing happen once myDictonary.Remove("foo") is called?

What is the point of _myDictonary["foo"] = null;

edit: To clarify - when I said "remove the count by one" I meant the following:
- myDictonary["foo"] originally points to an object. That means the object has one or more things referencing it.
- Once myDictonary["foo"] is set to null it is no longer referencing said object. This means that object has one less thing referencing it.

7
задан JSWork 7 March 2011 в 18:10
поделиться