Explicitly freeing memory in c#

前端 未结 9 707
刺人心
刺人心 2020-12-01 01:12

I\'ve create a c# application which uses up 150mb of memory (private bytes), mainly due to a big dictionary:

Dictionary Txns = new Diction         


        
9条回答
  •  抹茶落季
    2020-12-01 02:07

    Most probably you have a hidden reference to the dictionary somewhere else. Thus the dictionary is not collected, but if you Clear() it, the contents get collected.

    As others have already noted, forcing the GC is not recommended. This might lead to memory being pushed into higher "generations" which are not often collected, thereby wasting more memory than gained in the long run.

提交回复
热议问题