How substring() method of string class create memory leaks?



How substring() method of string class create memory leaks?..

Answer / 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

More Advanced Java Interview Questions

What are the diff types of exception?

1 Answers  


What is the difference between a stub and a skeleton?

9 Answers   ABC, College School Exams Tests, Geoservices, Polaris, Qualcomm, Rajiv Gandhi College of Engineering and Technology RGCET, UTIITSL, Wipro,


What are the purpose of introspection?

1 Answers  


How to implement dphibernate to activate lazy loading in Flex with java ?thanx in advance!

1 Answers  


Difference between DurableSubscription and non- DurableSubscription?

1 Answers  


What is the difference between system.out ,system.err and system.in?

1 Answers  


What is the RMI and Socket?

1 Answers  


what is the Remote Stub?

1 Answers  


if i know the lenght of collection in hand, should I use Array or Arraylist? justify

1 Answers   iTrust,


Explain the life cycle of servlet?

3 Answers   Cognizant, HCL,


Explain the purposes of methods wait(), notify(), notifyAll ()?

2 Answers  


What is ioc concept?

1 Answers  


Categories