3 ms·
How huge typical strings are that this is a problem? It could be a problem for arrays but seems unlikely for strings.
by xfer 6y ago
How huge typical strings are that this is a problem? It could be a problem for arrays but seems unlikely for strings.
- Someone 6y agoSome strings start live as part of multi-megabyte text files that get slurped in. Happened quite a bit with HTML/XML parsers. Workaround was to do new String(s.substring(…)) about everywhere. Real world case (with few details) at https://stackoverflow.com/questions/10951812/java-not-garbage-collecting-memory https://stackoverflow.com/questions/10951812/java-not-garbag.... Also, using slices doesn’t come for free; it makes all String objects larger because, apart from the reference to the underlying character array, an offset and length must be kept around.