Static data initialization

I've read online that type static data is lazily initialized on its first access. My question is: once that lazy initialization is complete, is the code generated to do the initialization discarded? Or, is it simply dead code for the remainder of the execution lifespan? A project I'm working on is trying to weigh the advantages of creating a non-trivial amount of dictionary data using static declarations vs parsing them out of json.

Thanks in advance for any experience, knowledge, or thoughts you may have on the matter.

If you declare say dictionary or array as static then that data will remain in memory for the life of the application. Static initializers are not cleaned automatically but then since you are only interested in reducing memory footprint, once you are done simply empty the dictionary or array and your memory will be freed.

My question is not about the data of the dictionary itself but the code that initializes it to its static values. Is that compiler generated initialization code ever discarded or is it stuck in memory for the life of app?

That is common between instance or static initialization. The class blue prints are loaded and linger on for efficiency purposes as long as possible and unloaded based on memory needs.

Terms of Service

Privacy Policy

Cookie Policy