.NET OutOfMemoryException

Почему это:

class OutOfMemoryTest02
{
    static void Main()
    {
        string value = new string('a', int.MaxValue);
    }
}

Вызывает исключение; но это не так:

class OutOfMemoryTest
{
    private static void Main()
    {
        Int64 i = 0;
        ArrayList l = new ArrayList();
        while (true)
        {
            l.Add(new String('c', 1024));

            i++;
        }
    }
}

В чем разница?

12
задан Bill the Lizard 23 February 2012 в 11:41
поделиться