21

Just faced with strange issue. When i type

java -version

i got

Error occurred during initialization of VM
Could not reserve enough space for object heap
Could not create the Java virtual machine.

.

java -Xms64m -Xmx64m -version

This command works fine

java version "1.6.0_24"
Java(TM) SE Runtime Environment (build 1.6.0_24-b07)
Java HotSpot(TM) Client VM (build 19.1-b02, mixed mode)

If i change xms, xmx to 128m, i get error again.

Using top command and free -m i can see, that i got over 192 mb free, so why i still get this error ?

Mem:    262144k total,    64760k used,   197384k free,        0k buffers
Swap:        0k total,        0k used,        0k free,        0k cached

Thank you

user12384512
  • 3,362
  • 10
  • 61
  • 97
  • I suddenly had this problem today - turns out I had switched to OpenJDK JRE 7. Normally I'm using Oracle JDK 8 which does not show this problem - at least not with a small number of VMs. – Stefan Reich Jul 04 '16 at 20:16

3 Answers3

14

I had the same problem when using a 32 bit version of java in a 64 bit environment. When using 64 java in a 64 OS it was ok.

RandomSeed
  • 29,301
  • 6
  • 52
  • 87
Yamada
  • 723
  • 6
  • 23
  • I have the same problem. Using 32bit Java on a 64bit system. Starting with Xmx1024 resulted in the above error. Starting with Xmx512 works fine! – T3rm1 Feb 10 '14 at 14:04
  • I had the same problem. I was using 32bit JRE on my 64bit PC. I changed the JRE to 64bit system and my problem is solved. – Devrim Oct 22 '14 at 09:02
11

It looks like the machine you're trying to run this on has only 256 MB memory.

Maybe the JVM tries to allocate a large, contiguous block of 64 MB memory. The 192 MB that you have free might be fragmented into smaller pieces, so that there is no contiguous block of 64 MB free to allocate.

Try starting your Java program with a smaller heap size, for example:

java -Xms16m ...
Jesper
  • 202,709
  • 46
  • 318
  • 350
  • Yes, my machine got only 256 mb, with -Xms16m and -Xms64m it works fine. But 64 is not enough for my needs. Can it be fixed somehow, so i can use 128 mb ? – user12384512 Jul 10 '11 at 16:20
  • Note that `-Xms` sets the initial heap size (`-Xmx` sets the maximum heap size). Does your program really need an **initial** heap size of 64 MB? Why not let the JVM grow it automatically? – Jesper Jul 10 '11 at 16:23
  • Yes, i know. But it does not really matter. Since java -Xms16m -Xmx128m -version failed too – user12384512 Jul 10 '11 at 16:28
  • 1
    It's going to be difficult to allocate 128 MB for the Java heap if the computer only has 256 MB RAM. The OS etc. also need memory. – Jesper Jul 10 '11 at 18:06
5

According to this post this error message means:

Heap size is larger than your computer's physical memory.

Edit: Heap is not the only memory that is reserved, I suppose. At least there are other JVM settings like PermGenSpace that ask for the memory. With heap size 128M and a PermGenSpace of 64M you already fill the space available.

Why not downsize other memory settings to free up space for the heap?

mico
  • 12,730
  • 12
  • 59
  • 99