I am monitoring my java application through JProfiler when I came across a scenario where 2 almost segments of code resulted in different memory usage.
The code segments are
// Case 1
for (String record : thisLine.split(","))
and
// Case 2
String[] rowData = thisLine.split(",");
for (String record : rowData)
The memory usage in Case 1 exceeds that of Case 2 by 100 MB (approx). I do not understand what is causing such a high memory spike for Case 1.
Some additional informations :
- thisLine is a String containing csv values
- The for loop in both the cases runs 1500 times (since there are 1500 csv values)