I have a private field in a class which is a dictionary of dictionaries.
private readonly Dictionary<string, Dictionary<int, int>>
myDict = new Dictionary<string, Dictionary<int, int>>();
What's the best practice regarding clearing myDict
? Do I have to loop on all the values and call Clear on each or is it enough if I just called Clear on myDict
??
I'm looking for the best performance too.
If you call Clear()
, it will clear the master dictionary. If there are no references any more to the inner dictionaries, the garbage collector will clean them up, so there is no need to call Clear()
on them. If they are still being referenced, you have to unreference those first on you might end up with an invalid state.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With