Today I checked the memory usage of my application and I found something that does not make sense to me. I expected to have more than one instance of an object that I do not dispose but when I check the diagnosis tool it only has one instance. Then I tried to run some tests to intentionally create more than one instance and check the memory and it was again one.
Imagine we have a class like this.
public class Car
{
public string Name {get;set;}
}
If I create 100 instance of this Car object in a loop I expected to have 100 objects in memory.
for (int i = 0; i < 100; i++)
{
var car = new Car();
}
But when I try this and check the memory I only see one instance of that object! I tried this with HttpClient too but still the same. I was wondering if I am missing something here and what is the point of CG in that case! I did so many googling and I was not able to find a proper answer so I thought maybe share it with you guys.