I have the following nested dictionaries:
Dictionary<int, Dictionary<string, object>> x;
Dictionary<int, SortedDictionary<long, Dictionary<string, object>>> y;
If I do x.Clear()
and y.Clear()
will all the nested objects clear and all the memory will be reused on the next garbage collection?
Or do I need to iterate on all the items and clear them manually?
If none of your objects are reachable from other parts of your code, they will all be garbage collected.
If this will be done on the next garbage collection, depends on the generation that they belong to.
This article from Jeffrey Richter explains a lot.
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