Find the bugThe concurrent memory buster

time to read 1 min | 158 words

This is test code, to check something out, and it blew up in my face after consuming all the memory on the machine.

Can you see why?

Parallel.For(0, 10, i =>
{
    var list = new List<int>();
    int c = 0;
    int sum = 0;
    for (int x = 0; x < 10000; i++)
    {
        if (c != list.Capacity)
        {
            c = list.Capacity;
            sum += c;
        }
        list.Add(sum);
    }
});

More posts in "Find the bug" series:

  1. (29 Feb 2016) When you can't rely on your own identity
  2. (05 Jan 2016) The case of the degrading system–Answer
  3. (04 Jan 2016) The case of the degrading system
  4. (11 Sep 2015) The concurrent memory buster
  5. (20 Apr 2011) Why do I get a Null Reference Exception?
  6. (25 Nov 2010) A broken tree
  7. (13 Aug 2010) RavenDB HiLo implementation
  8. (25 Jul 2010) Accidental code reviews