2 ms·
They're really different issues. Deduplication reduces the memory consumption of duplicate strings. Compact strings reduce the memory consumption of ascii strin
by hyperpape 9y ago
They're really different issues. Deduplication reduces the memory consumption of duplicate strings. Compact strings reduce the memory consumption of ascii strings, regardless of whether they're unique or mostly duplicates.
So depending on your situation, you could want either, both, or neither. There is some overlap, however. If you have a lot of ascii strings but also a high level of duplication, either approach will save some memory, but if deduplication by itself saves x bytes, and compact strings saves y, using both will save a lot less than x + y bytes.
And, like the later poster says, don't use String.intern() for deduplication.
- shock 9y ago> They're really different issues. They're different fixes for the same problem: high memory usage. Depending on the situation you can use one or both, as you say.