Resolve the memory leak in JDK 1.6
subString = string.substring(3, 10) + "";
In above code, the string.substring(3, 10) will return the substring which point to original string array and the substring will not allow the garbage collection for old string (char value[]).
But when we add the empty string to offset, new string will form in constant pool with new char value[] array and we can overcome the problem of garbage collection of old string array.
No comments:
Post a Comment