I have been doing a lot of research about static objects and the high vs low frequency heap. I understand that the high frequency heap is not garbage collected. My question is if I am instantiating an array or dictionary in a normal class as a static instance in a web server:
public class Lookup
{
private static readonly Lookup instance = new Lookup();
private Dictionary<Decimal, Enum> _enums;
public static Enum GetEnum(Decimal value)
{
return instance._enums[value];
}
Lookup()
{
_enums = new Dictionary<decimal, Enum>();
_enums[1.1] = enum.enum1;
_enums[2.2] = enum.enum2;
_enums[3.3] = enum.enum3;
_enums[4.4] = enum.enum4;
//...etc
_enums[5000] = enum.enum5000;
}
}
The static instance is placed in High Frequence heap. Is the dictionary there too? Or maybe is there a pointer to the low frequency heap?
When creating a dictionary/array of default size and adding the values one at a time, the dictionary has to re-size itself repeatedly. As I understand it, it does this by allocating new memory and copying over the data, and the old dictionary gets Garbage Collected eventually. But if the High frequency heap is not collected, would this cause multiple copies of the array to reside in the HF heap? Or if the HF heap has only pointers to the LF heap, do they not get collected because there are references residing in HF heap still?
Edit: Thanks Alexei Levenkov, this is currently running on the web and we are getting really unusual out of memory exceptions killing our server when this GetEnum is called. As to the references, here are a few:
http://www.codeproject.com/Articles/15269/Static-Keyword-Demystified