String storage can be quite expensive. Using random String of avarage ~ 80 chars long, 3 000 000 strings can cosume almoust 1GB
public static void main(String[] args) {
List<String> list = new ArrayList<>();
String base = RandomStringUtils.random(80);
long i = 0;
try {
while (i < 3e6) {
list.add(base + i++);
}
} finally {
System.out.println("Count:" + list.size());
System.out.println("Memory:" + Runtime.getRuntime().totalMemory() / 1024d / 1024d);
}
}
Output:
Count:3000000
Memory:981.5
Try to wrap your piece of code where you are reading your file with the same try-finally
block i have made here. When error will popout, you will get approx ammount of memory you are consuming at that point, and what percentage of file you have managed already to read. This will get you the idea of how much more memory you will need.
Moreover you will know if your -Xmx
directive works, because if it will crash around lets say 500mb it is either ommited by netbeans, or there is no mo available memory it the system.