adspace
How substring() method of string class create memory leaks?
Answer Posted / Rahul G. Momin
The substring() method in Java does not create memory leaks by itself. However, if the original String object is modified after a substring is created from it, then both the original and the substring will reference the same underlying character array. When one of them goes out of scope (due to garbage collection), the other might still hold a reference to it, causing a memory leak. To avoid this issue, create new String objects for each substring.
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
No New Questions to Answer in this Category !! You can
Post New Questions
Answer Questions in Different Category