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

原文地址:https://www.cnblogs.com/zbw911/p/3464551.html