0

Increase the heap size of JVM but doesn't work

For increasing the JVM heap size I set it on 9GB but the result is as the same as 1GB. I need to allocate more memory for project. I tested the result after increasing the JVM heap size for a simple code: int[][] a = new int[32000][32000] int[][] b = new int[32000][32000] The first line is ok but the second line get me heap error. https://www.linkpicture.com/q/IMG_20210602_171503_701.jpg 2(4 × 32000 × 32000) = 2 × 4GB = 8 GB And I set the JVM on 9000MB but still the error! What is the problem, is anyone understand what's the problem? Thanks if you share =)

2nd Jun 2021, 9:13 PM
I U
4 Answers
+ 6
Many factors I can think of (may or may not solve your issue) -The heap size in Java used to be limited so check your Java version --32bit versions (jvm) were definitely limited; 64 bit limits to your machine -Does your machine allow for 9GB --The OS could be stopping you from doing this (Other running processes use more allocated space than they're actually using for safety). Less likely but could be --Your hardware may not be capable of handling that much (RAM) -Maybe you mistyped (it would throw an error so this is less likely) or used a wrong flag
2nd Jun 2021, 9:53 PM
「HAPPY TO HELP」
「HAPPY TO HELP」 - avatar
+ 5
that would depend on your OS so you can search that up and check the distribution e.g. windows 10, 8, 7 etc. Linux ubuntu, Debian, Arch No error => flags are ok i assume. I agree with you it should but it could be unsafe. if you have 16 and want to take 9 it should be no problem in my eyes 🤔 huh that's weird... did you try to access or set a value in the array? that should throw an error (seg fault or OOB) if it didn't actually allocate all that memory Yes this is confusing 😂 it shouldn't have worked for 1 i gtg in a little bit so sorry for late reply!
2nd Jun 2021, 10:18 PM
「HAPPY TO HELP」
「HAPPY TO HELP」 - avatar
+ 1
How can I know if the machine allow to do this? When I set it and reset the IDE I got no error I have 16GB of RAM so why the program cannot take half of it for itself? Another question, when the JVM is set to 1GB.. this line of code is working ok and I got no error: 2D int array with 32000×32000 size which as I calculate it it must need about 4GB for allocating this arr So how is this working with 1GB heap size for JVM but when I set that to 4GB cannot allocate two of that 2d int array with that size I got confused a lot and no searching helped me for that
2nd Jun 2021, 10:05 PM
I U
+ 1
Thanks! Hmm, Ill see what to do
3rd Jun 2021, 11:02 AM
I U