Intern string literals misunderstanding?

String literals get interned automatically (so, if your code contains “lalala” 1000 times, only one instance will exist).

Such strings will not get GC’d and any time they are referenced the reference will be the interned one.


string.Intern is there for strings that are not literals – say from user input or read from a file or database and that you know will be repeated very often and as such are worth interning for the lifetime of the process.

Leave a Comment