You have to calculate the space that array needs. If it is over 2048M then you'll receive an OutOfMemoryError
.
In your case you try to allocate an array of 10000 x 10000
which is 100.000.000
.
A primitive int
occupies 4
bytes. This means that the whole array takes
100.000.000 * 4
bytes which is 0,37 GB
of space.
So it seems that there is something else in your program which caueses the error. For example if you try to allocate multiple arrays in a loop then you can run out of memory real quick.
It can be a problem if your hardware does not have 2048M
of memory.
It is also possible that before using -Xmx2048m
you had for example -Xmx512m
which might be too small for your array.