Reputation: 2869
I have a relatively large strings that will not change during my program run. Is it wise to mark them as const string
(in order to gain some imaginary performance benefits) ? Will the memory allocated for these string will be eventually garbage collected ?
Upvotes: 5
Views: 848
Reputation: 755091
No it will not. Const strings are stored in metadata and hence are not ever collected unless the containing assembly is removed from the process. This will only happen on AppDomain unload. All uses of this string are simply references to this memory.
Upvotes: 18