In the following code segment, I am wondering why testvectors is not collected after the function call. I see memory usage go up to 270Mb and then stay there forever.
This function is directly called from Main.
private static void increaseMemoryUsage()
{
List<List<float>> testvectors = new List<List<float>>();
int vectorNum = 250 * 250;
Random rand = new Random();
for (int i = 0; i < vectorNum; i++)
{
List<Single> vec = new List<Single>();
for (int j = 0; j < 1000; j++)
{
vec.Add((Single)rand.NextDouble());
}
testvectors.Add(vec);
}
}
Don’t confuse garbage collection with reference counting. The memory is freed when the runtime decides, not always when it’s no longer referenced. To quote:
Read this if you’re interested:
http://msdn.microsoft.com/en-us/library/0xy59wtx.aspx