I'm developing a Windows Service with C# and .NET Framework 4.6.2 and Entity Framework 6.1.3.
I have a Web API interface on that service and in one Controller's method I create a Dictionary with more than one million strings:
Dictionary<string, List<string>> codes;
This Dictionary is created inside another method:
codes = GetCodesAsDictionary(connectionString, productionId);
I pass this variable to a static method from a static class.
One Visual Studio 2015's memory profiler I see how memory grows to 1,1Gb when I call this method, but when the method ends, the memory keep as 1,1Gb.
If I call the method again, memory grows again to 2Gb, and after method finishes, memory goes to 1,1Gb again.
I have tried to pass the codes
variable as reference, but I get the same memory allocation. I have to stop the service and re-run it again to release that 1,1Gb. By the way, I pass it by reference because I don't want that the static method makes a copy of it.
Do you know why it doesn't release such amount of memory after method ends?
UPDATE:
I have changed the static class with an instance class (copying the method from static class) and I get the same result (1,1Gb memory allocated).
SECOND UPDATE:
I have also changed how the dictionary is created:
Dictionary<string, List<string>> codes = null;
GetCodesAsDictionary(connectionString, productionId, out codes);
And I get the same result: 1,1Gb memory allocated.
THIRD UPDATE:
I have changed the Dictionary
with a KeyValuePair<byte, string[]>[]
and I get the same result, 1,1Gb allocated. Now, instead of using a string
as key, I'm using byte.