Java / Using String
Does substring method cause memory leak?
It was and it is fixed since JDK 1.7. The issue was substring method creates new String object keeping a reference to the whole char array, thus inadvertently keep a reference to a very big character array with just a one character string.
It was fixed in Java 7, rather than sharing original character array, substring method creates a copy of it and creates new String.
More Related questions...