3 ms·
> No, that's not correct. See the commit for yourself! They removed the sharing between string values when you created a substring a while ago. https://github
by chrisseaton 6y ago
> No, that's not correct.
See the commit for yourself! They removed the sharing between string values when you created a substring a while ago.
https://github.com/openjdk/jdk/commit/f55750d05a04484b719220f21e34c05017f001fd https://github.com/openjdk/jdk/commit/f55750d05a04484b719220...
- hn_throwaway_99 6y agoSorry, yes, we were talking about different things. Calling String.substring() used to not copy the original char array, and would instead just store an offset and length in the new String, but still point to the char array of the original String. This could cause memory leaks, and the commit you referenced fixes that. I was referring to String interning, where literals defined in code are only created once even if they are duplicated, and the API provides String.intern() to get the "canonical" instance of a String.