Estimate the memory strings occupy including object overhead and encoding.
Short strings are dominated by object overhead rather than content, so a forty-byte header on a ten-character string more than doubles its cost. Interning collapses duplicates to a single copy plus a reference. String duplication is extremely common in parsed data, which is why interning often reclaims a third or more of heap memory.
String Memory
Bytes per string = object overhead + length × bytes per character
Bytes per string = object overhead + length × bytes per character Short strings are dominated by object overhead rather than content, so a forty-byte header on a ten-character string more than doubles its cost. Interning collapses duplicates to a single copy plus a reference.
String duplication is extremely common in parsed data, which is why interning often reclaims a third or more of heap memory.
This calculator takes 5 inputs: Number of strings, Average length in characters, Bytes per character, Per-string object overhead, Share that are duplicates. The pre-filled defaults are a realistic starting point — replace them with figures from your own environment for a result you can act on.