Is const string suitable for garbage collection?

I have relatively large lines that will not change during my program launch. Is it possible to mark them as const string (to get some imaginary performance benefits)? Will the memory allocated for this line end up garbage collection?

+4
source share
1 answer

No, it will not. Constant strings are stored in metadata and, therefore, are never collected unless the containing assembly is removed from the process. This will happen only when the AppDomain is unloaded. All use of this line is just references to this memory.

+17
source

All Articles