C# 使用List<T> 内存溢出

class Program
   {
       static void Main(string[] args)
       {
           var all = new List<string>();
           for (var i = 0; i < 999999999999; i++)
           {
               var b = new List<string>();

               for (var j = 0; j < 1000; j++)
               {
                   b.Add(new Guid().ToString());

                   try
                   {
                       all.AddRange(b);
                   }
                   catch (Exception)
                   {
                       Console.WriteLine(all.Count);

                   }
               }

           }

           Console.WriteLine(all.Count);

       }
   }

 

 

image

posted @ 2013-12-09 00:58  张保维  阅读(2526)  评论(0编辑  收藏  举报