Garbage collector: .NET 4.6 vs .NET Core 1.1

I found an interesting thing, but couldn't figure out why it works.

I have created two applications in Visual Studio 2017:

  • Console Application (.NET Framework) - .NET 4.6
  • Console Application (.NET Core) - .NET Core 1.1

Then I wrote the code:

class TestApp
{
    static void Main(string[] args)
    {
        var objectsList = new List<Entity>();
        for (int i = 0; i < 100000; i++)
        {
            objectsList.Add(new Entity());
            if (i % 1000 == 0)
            {
                Console.WriteLine(i);
            }
        }

        Console.WriteLine("DONE!");
        Console.ReadKey();
    }

    class Entity
    {
        public string Text1 { get; set; }
        public string Text2 { get; set; }
        public DateTime Date1 { get; set; }
        public DateTime Date2 { get; set; }
        public int Number1 { get; set; }
        public int Number2 { get; set; }
        public long LongNumber1 { get; set; }
        public long LongNumber2 { get; set; }
        public List<int> Numbers { get; set; }

        public Entity()
        {
            Text1 = Guid.NewGuid().ToString();
            Text2 = Guid.NewGuid().ToString();
            Date1 = DateTime.MaxValue;
            Date2 = DateTime.MinValue;
            Number1 = int.MaxValue;
            Number2 = int.MinValue;
            LongNumber1 = long.MaxValue;
            LongNumber2 = long.MinValue;
            Numbers = new List<int>();

            for (int i = 0; i < 10000; i++)
                Numbers.Add(int.MaxValue);
        }
    }
}

      

I ran this code in two apps and saw that .NET Core runs it without any problem, while the .NET Framework throws a System.OutOfMemoryException .

QUESTION: Looks like the .NET Core garbage collector performs better, doesn't it? But why is this so? Can someone explain this to me or give some sources where I can find some explanation?

PS My computer has about 3 GB of free memory when running applications.

+3
garbage-collection c # .net out-of-memory .net-core


source to share


No one has answered this question yet

Check out similar questions:

1939
Difference between decimal, float and double in .NET?
946
How to avoid curly braces (curly braces) in a format string in .NET.
890
How can I get the app path in a .NET console app?
841
Sending email in .NET via Gmail
709
Easiest way to split a string to newlines in .NET?
700
What is the difference between .NET Core and .NET Standard Class project types?
681
.NET String.Format () to add commas to thousands of number places
287
What is .NET Core?
243
Why doesn't C ++ have a garbage collector?
0
.net date format on Linux



All Articles
Loading...
X
Show
Funny
Dev
Pics