I am working with 2D int arrays in Java, that are square and can have ~30000 elements in a row and column, which means there are 30000^2*4 bytes in the array, which is less than 5GB (and I have much more than 5GB of memory available).
My basic structure of the program is this:
public class A {
public static void main(String[] args) {
Graph g = ...; // read from file
System.out.println(B.computeSomethingBig(g));
}
}
public class B {
public static computeSomethingBig(Graph g) {
int numVertices = g.numVertices();
System.out.println(numVertices); // ~30000 maximum
int[][] array = new int[numVertices][numVertices];
// ... other computations
}
}
Now, in Eclipse, I am running main in class A with these arguments:
-Xms5g -Xmx10g
I have numVertices print out a value around 30000, and setting the minimum heap size (-Xms) seems more than necessary. However, I get:
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
new T[int_value][int_value]initializes both dimensions (new T[int_value][/*empty*/]would do only first) and @Ryanintis indeed 4 bytes. Creating (only)int[30000][30000]works for me, in 7u55 on x64 with-Xmx4G, andRuntime .totalMemory() - .freeMemory()confirms it uses slightly over 3.6e9 bytes.