.net - Explicitly freeing memory in c# -


I have created an AC # application which uses 150MB of memory (private bytes), mainly due to a large dictionary :

  dictionary & lt; String, int & gt; Txn = new dictionary & lt; String, int & gt; ();  

I was wondering how to get rid of this memory. I have tried to:

  Txns = null; GC.Collect ();  

But this does not seem to make as much pit in my private bytes - they can say from 155mb to 145mb. Any clues?

Thanks -

OK, I get more luck with this code but why?

  Txns.Clear (); // & lt; - makes all the difference Txns = null; GC.Collect ();  

-Edit -

People who say, 'GC Do not use 'collect', it is appropriate (I am not going to argue over it, other than saying that you can come through my background), but it does not really answer my question: if If I clean the transaction list first then why does the garbage collector free only memory? Should it not free any memory in any way, because the dictionary has been removed?

Refers to private byte process' memory usage When the objects are collected, the associated memory segment or OS may not be free. CLR manages memory at the OS level and is not free from memory allocation and free as there is no reason to free every piece of memory immediately because it is likely that this application will later request more memory.


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -