I have written a code. The problem that I am facing is that when the "j" of for loop exceeds 1000 I start to get an error of "GC overhead limit exceeded". If I increase the allocated memory to 4GB I can iterate upto 2000 after which the same problem occurs. I want to keep this option of increasing the memory as the last resort and want to try to scale my code. The compiler highlights a problem with the statements where I have placed an arrow. Can someone please guide me that what could be the possible error here. I have already visited this question Error java.lang.OutOfMemoryError: GC overhead limit exceeded
for (int j=1; j<=num_doc; j++) {
List<Integer> list1 = new ArrayList<Integer>(Collections.nCopies(129039, 0));
BufferedReader fl = new BufferedReader(new FileReader(dataFolder+"file"+ " ("+j+")"+".int"));
String line1;
while((line1=fl.readLine()) != null) {
String[] arr=line1.split(" ");//<---------------------
line1="";
int k = Integer.parseInt(arr[0]);
Arrays.fill(arr, "");
numb=numb+1;
int temp=(list1.get(k))+1;
list1.set(k, temp);
}
F_d.add(numb);
numb=0;
fl.close();
ls2d.add(new ArrayList<Integer>(list1));//<---------------------
list1.clear();
}