We normally give the value for -Xmx and -Xms while executing a Java application and increase the heap size as per our requirement (to avoid out of memory error).
My question is how do we calculate the memory requirement? Let us take below example :
for(int i=0 ; i<1000; i++){
try{
array.add(new ArrayList<Integer>(100000000));
}catch(OutOfMemoryError e){
}
}
First this program runs with -Xmx128M and later run using -Xmx256M. Will the program run in both the conditions? If not then what could be the reason and can we calculate the appropriate value of memory argument needed to run this program?