Class reference and GC loop in C #

I saw someone write int code in the following style:

Dictionary<string,SomeClass> dict = new Dictionary<string,SomeClass>();
...    
dict.Add(key,someClass);    
...    
dict[key] = null;    
dict.Remove(key);

      

I wonder if it's needed dict[key] = null;

. Does this mean informing the GC? But what someClass

is not mentioned anywhere else, Is it redundant?

+3


source to share


1 answer


Yes, he is superfluous. If you are going to delete the key anyway, it makes no sense to change the entry to be null first. It shouldn't make any difference for garbage collection anywhere.



+7


source







All Articles