I saw some one wrote code int the following style:
Dictionary<string,SomeClass> dict = new Dictionary<string,SomeClass>();
...
dict.Add(key,someClass);
...
dict[key] = null;
dict.Remove(key);
I wonder if the dict[key] = null;
necessary. Does that mean to inform the GC?
But that someClass
is nowhere else referenced,
Is it redundant?
Yes, it's redundant. If you're going to remove the key anyway, there's no point in changing the entry to have a null value first. It should make no difference to garbage collection anywhere.
See more on this question at Stackoverflow