Can the following code cause a memory leak? Would using a StringBuffer actually improve memory usage?
A little background: A coworker has been pushing his theories on memory leaks, and this is code he has identified as being problem code (without doing any sort of profiling), which he claims can cause a memory leak. I disagree with this, so I thought I'd put it to some other developers to get a third party opinion.
List partCollection = new ArrayList()
String partKeyID = null;
String sPartNbr = null;
String partDescription = null;
while(rsPartRes.next())
{
partKeyID = rsPartRes.getString("PART_KEY_ID");
sPartNbr = rsPartRes.getString("PART_NBR");
partDescription = rsPartRes.getString("PART_DESC");
SomeValueObject someValueObject = new SomeValueObject();
someValueObject.setPartKeyID(partKeyID);
someValueObject.setSPartNbr(sPartNbr);
someValueObject.setPartDescription(partDescription);
partCollection.add(someValueObject);
}
Assume that rsPartRes is a ResultSet in this code which could contain 100+ records. Basically, his concern is that because we are looping through this result set and not using a StringBuffer (which, in this case, I'm not even sure HOW you would use one), that it could be causing memory leaks. Is there ANY case that anyone sees here where this could possibly cause memory leaks or performance issues...?