Memory usage of byte arrays in Java
See the English answer > java process memory check test2
public class Main{ public static void main(String[] args){ byte[] arr = new byte[1504935936]; } }
Why do I have an "outofmemoryerror: Java heap space" - exception if I give the program 2 GB of ram and
java -Xmx2048M Main
with
java -Xmx2153M Main
Useful Why do you need so much RAM?
Solution
It may be because the Java heap is used and segmented by other data in the program
The byte array needs to be allocated as a continuous 1.5 GB memory block in Java heap space (this is not required by the Java language specification, but AFAIK is the actual working mode of all current JVM implementations.) Some of your heap space is being consumed, and perhaps more importantly, by other memory allocations that occur in the program The Java - xmx2153m main may make your whole heap have a continuous 1.5 GB space. How much time is left for you to your allocated time
If you cut this large array into 100 small arrays, its size is 1 / 100, because it is not as sensitive as heap fragments