A few years ago, I wrote this in c#:
private string InternOrNot(string v)
{
if (v == "EUREX");
return "EUREX";
else
return v;
}
This method may look useless, but it's not. In fact, it dramatically decreased the memory usage of one of our servers.
This server acted as a data cache for financial data received on a Tibco Rv real-time bus. Around 20% of the overall received data was just the "EUREX" string, so the server holded references to millions of "EUREX" string objects.
By calling this method just before stocking the data, if the data to store is "EUREX", the initial reference is just discarded (and can be GCed) while I store a reference to my own unique interned "EUREX" string.
If you don't know about string Interning, you may want to look at this page.