1

I have a code like this:

 public Integer detailMigration(Integer p1, Integer p2) {
           List<Info> memberInfo = this.memberInfoRepository.findBymemberIdBetween(p1, p2);
           Integer count = 0;
           for (Info pInfo : memberInfo) {
               String details = pInfo.getMemberDetails();
               //Do something
               count++;                
           }
           return count;
       }

`List<Info> memberInfo = this.memberInfoRepository.findBymemberIdBetween(p1, p2);` returns the list of member tuples from the DB table.

Now when i am iterating over tuple in for loop:

for (Info pInfo : memberInfo) {
               String details = pInfo.getMemberDetails();
               //Do something
               count++;                
           }

is String details = pInfo.getMemberDetails();will going to add new string object in string pool or not? As i am getting memory leak with the flow of above code. Suppose in web application , i am frequently making DB query containing String type column, so as soon as i fetch them from DB , do they get add in String pool. IMO , it should get add in pool., and its in permgen , so is it not liable for GC. Kindly correct me to give exact scenario What should be the correct way?

user3363969
  • 233
  • 1
  • 4
  • 15
  • You could try a string builder and check if that helps – Anudeep Bulla Sep 19 '14 at 10:27
  • 1
    That depends on the implementation details of `pInfo.getMemberDetails`, can you share this? – Axel Amthor Sep 19 '14 at 10:28
  • getMembersDetails just fetching data from DB via JPA call and returning data. – user3363969 Sep 19 '14 at 10:33
  • Only String constants and Strings you call intern() on are put into the memory pool. And even that only up to Java 6. Regular String objects are just kept on the heap, and are garbage-collected. – Thomas Stets Sep 19 '14 at 10:39
  • To find memory leaks you can make a heap dump and analyze it with a tool like MAT (http://www.eclipse.org/mat/) – Thomas Stets Sep 19 '14 at 10:40
  • You present no evidence of a memory leak. – Raedwald Sep 20 '14 at 09:31
  • possible duplicate of [When are Java Strings interned?](http://stackoverflow.com/questions/3451145/when-are-java-strings-interned) – Raedwald Sep 20 '14 at 09:34
  • Not all `String` objects are placed in the string pool. Only constants and exolicitly `intern()`-ed values. See http://stackoverflow.com/questions/3451145/when-are-java-strings-interned – Raedwald Sep 20 '14 at 09:36

0 Answers0