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?