SunnyX
asked on
Requested array size exceeds VM limit
Let say I'm trying to create array with size of Integer.MAX_VALUE
"java.lang.OutOfMemoryErro r: Requested array size exceeds VM limit"
Because I use the Win10, I thought that this is because Win10 max limit for applicaiton is 2 Gb , but in order to create array with size Integer.MAX_VALUE I would need 4Gb space. ( 2^32 = 4 * 1024 * 1024 * 1024 )
However, when I tried to make int[] ar = rndArray(Integer.MAX_VALUE -2 );
I get "java.lang.OutOfMemoryErro r: Java heap space" - this error probably go from intellij idea that I use which is limit heap memory size 128 Mb
So I believe my assuption is failed, because Integer.MAX_VALUE -2 far more than 128 Mb
It is also not bacause my JMV in 32bit mode bacause I check my java -version
So could somebody tell me why I cannot create array with size Integer.MAX_VALUE
P.S. I have 8.0 DDR3 RAM overall. The Win10 RAM monitor show me that I've avaliable 4.2Gb RAM
public static void main(String[] args) {
int[] ints = new int[Integer.MAX_VALUE];
}
However, I get an error : "java.lang.OutOfMemoryErro
Because I use the Win10, I thought that this is because Win10 max limit for applicaiton is 2 Gb , but in order to create array with size Integer.MAX_VALUE I would need 4Gb space. ( 2^32 = 4 * 1024 * 1024 * 1024 )
However, when I tried to make int[] ar = rndArray(Integer.MAX_VALUE
I get "java.lang.OutOfMemoryErro
So I believe my assuption is failed, because Integer.MAX_VALUE -2 far more than 128 Mb
It is also not bacause my JMV in 32bit mode bacause I check my java -version
Java(TM) SE Runtime Environment (build 1.8.0_101-b13)and JMV 32bit has ~1,3Gb limit
Java HotSpot(TM) 64-Bit Server VM (build 25.101-b13, mixed mode)
So could somebody tell me why I cannot create array with size Integer.MAX_VALUE
P.S. I have 8.0 DDR3 RAM overall. The Win10 RAM monitor show me that I've avaliable 4.2Gb RAM
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER