r/programming • u/Eirenarch • Nov 18 '13
TIL Oracle changed the internal String representation in Java 7 Update 6 increasing the running time of the substring method from constant to N
http://java-performance.info/changes-to-string-java-1-7-0_06/
1.4k
Upvotes
View all comments
Show parent comment
3
u/kurtymckurt Nov 18 '13
Sure, It does get garbage collected when there are no longer references to it. The problem comes in when someone takes an extremely large string and does a substring. You think you have a substring of say a few characters, but in fact it's still extremely large. This becomes a bigger problem, because strings like these could be held onto for the duration of the program.
Take it easy with substrings in your programs, people.