string.Intern(…) – Minimising Memory Footprint

I had a one particular view (in the UI) that loaded denormalised data with many repetitive strings. There was nothing much we could do to minimise the volume of the data loaded, however during profiling I realised that most memory was consumer by strings, and most of them were the same.

I remembered a feature of a ‘string’ to intern the value i.e. two or more string having the same value would point to the same memory location without duplication. Applying this technique allowed me to save about 2/3 of the memory consumed. There was one downside though, this memory would never be reclaimed.

So now I’m thinking of writing my own interning using WeakReference

Blog at

Up ↑