I have been playing around with GC.GetTotalMemory(). When I create a local variable of type Titles in the example below, the consumed amount of memory increases by 6276 bytes. What’s going on here?
class Program
{
enum Titles { Mr, Ms, Mrs, Dr };
static void Main(string[] args)
{
GetTotalMemory();
Titles t = Titles.Dr;
GetTotalMemory();
}
static void GetTotalMemory()
{
long bytes = GC.GetTotalMemory(true);
Console.WriteLine("{0}", bytes);
}
}
I think it is because allocator somewhere bite a big piece of memory. It will use it for more than one object. Try to do:
and see what happens.
here is what i see, and GetTotalMemory() is not so innocent:
outputs:
and this:
outputs:
actually you should not pay attention to small fluctuations of free memory:
🙂