What List TrimExcess() does and when to use it

  • Thread starter Thread starter Sudip_inn
  • Start date Start date
S

Sudip_inn

Guest
private void button2_Click(object sender, EventArgs e)
{
var before = System.Diagnostics.Process.GetCurrentProcess().VirtualMemorySize64;

List<string> lst1 = new List<string>();

for (int i = 0; i <= 1000000; i++)
{
lst1.Add("Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test ");
}

var after = System.Diagnostics.Process.GetCurrentProcess().VirtualMemorySize64;

lst1.Clear();
lst1.TrimExcess();

var current = System.Diagnostics.Process.GetCurrentProcess().VirtualMemorySize64;
}

i saw TrimExcess() clear memory for list instantly and it is bit better than list = null & GC.Collect....am i right?

one request that please tell me what List TrimExcess() does and when to use it ? please come with a example which explain the objective of List TrimExcess() . i want to understand the actual usage of TrimExcess() function.

thanks

Continue reading...
 

Similar threads

P
Replies
0
Views
176
Policy standard local admin account with Active Di
P
Back
Top