Say we have a class with 10000 const string members.
class Schema
{
//Average string length is 20
public const string ID1 = "some.constant.value";
public const string ID2 = "some.other.constant.value";
//...
}
Not all fields are referenced in the rest of the code. Only 10% of them is accessed on startup - their reference is assigned as a key to various dictionaries (thousands of Dictionary instances). I understand that const strings are interned - referencing a const string multiple times does not increase consumed memory by more than the size of the metadata token pointing to an offset in the interned string table.
I understand that the const strings are compiled into the assembly and thus influence the size of the compiled assembly.
At what exact time/event do these const strings consume runtime memory?
Will be all the memory needed for all the const strings taken at the time the assembly is loaded or is this delayed until the class is JIT compiled?
Can we decrease memory consumption after startup by changing something in the equation? (make the fields non-const, make the strings static fields?).
Let's assume a Winforms application (.NET 2.0).