This code doesn't do anything practical I was just seeing what would happen.
As far as I can tell, the only two variables that are preserved are the (eventually) massive string, and a neglible size int tracking the string's length.
On my machine, the string gets to be about 0.75GB at which point the OutOfMemoryException
occurs. At this stage Visual Studio is showing about 5GB of usage. So I'm wondering why there is a disparity.
var initialText = "Test content";
var text = initialText;
var length = text.Length;
while (true)
{
try
{
var currentLength = text.Length;
Console.WriteLine($"Current Length - {currentLength}");
Console.WriteLine($"Current Size in GB - {System.Text.Encoding.UTF8.GetByteCount(text)/1024.0/1024.0/1024.0}");
text = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(text));
Console.WriteLine($"Change In Size - {currentLength / (length + 0.0)}");
length = currentLength;
}
catch (OutOfMemoryException)
{
break;
}
}
As a second question, when I begin to run the code my machine has about 11GB free according to Task Manager, and when it hits the exception, it's gone up by about 3GB, which doesn't tally up with the above numbers. Any ideas?