C # how does a hashtable shrink when items are removed from a hash table?
3 answers
C # hashtables don't shrink; they only grow. The logic is important because the paraphrasing algorithm is VERY expensive to run; for most situations, the space saved by renaming to a smaller hash table will be completely covered by the cost of rephrasing. In particular, in automatic mode, when any deletions from the hash table may not be the last delete (it is impossible to determine from the hash table on an algorithmic basis), the potential value is simply not worth it.
If your hash table is shrinking significantly and you really want to reclaim space, I recommend just creating a new one (with the size you want) and copying the items to it.
+4
source to share