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
source to share
No one has answered this question yet
Check out similar questions: