Skip to content

Memory footprint of Dictionary

George George

Asked May 17, 2008, 3:51 AM EDT2 answers
Share
LinkedInX

Hello everyone,


I am migrating from C++ to C#. Two questions about memory footprint of Dictionary class object instance.

1.

If I call remove method to remove some elements from the Dictionary, will the memory footprint be reduced? (suppose there is no other reference to the removed item) I have some suspecision that Dictionary is not truly removing the element and just mark a flag or something, which still refer this removed item to block it from GCed.

2.

I have two ideas to reduce memory footprint of Dictionary, one is mentioned in (1), to remove some entries. The other is to create a new Dictionary instance, and insert only necessary items into the new Dictionary instance, and reference only the new Dictionary instance in the future.

Which way is better from memory footprint reduce perspective?


thanks in advance,
George

2 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • 0

    I used reflector to examine the code for Dictionary<,>.Remove and it does indeed remove the value. However, the answer to the larger question is probably doing an experiment to see if there is a difference either way, and if that difference is significant (I suspect not).

    0
  • 0

    Hi Ben,

     

    Any ideas to how to monitor the memory? I have never performed memory footprint monitor in C# applications yet. Any tools or APIs could I use?

     

    regards,

    George

    0