In .NET, clearing parent nested dictionaries frees up all memory while garbage collection?

I have the following nested dictionaries:

  • Dictionary<int, Dictionary<string, object>> x;
  • Dictionary<int, SortedDictionary<long, Dictionary<string, object>>> y;

If I execute x.Clear()and y.Clear(), will all nested objects be cleared and all memory will be reused in the next garbage collection?

Or do I need to iterate over all the elements and clean them manually?

+3
source share
3 answers

If none of your objects are accessible from other parts of your code, all of them will collect garbage.

If this is done in the next garbage collection, it depends on the generation to which they belong.

.

+4

: GC ( ) . , , .

, - , .

0

Maybe yes.

If you have links to elements in the dictionary, regardless of the type of the value parameter, then these objects will not be collected.

But if there are no links, then they will be assembled (at some point).

0
source

Source: https://habr.com/ru/post/1739297/


All Articles