Im trying to run my java application, but after some time it automatically stops and throws OutOfMemoryException: Java heap space. Now when i try to run it using (say) (-Xmx allocates the maximum heap memory)
java -Xmx2000m [AppName]
then it says
Error occured during initialization of VM
Could not reserve enough space for object heap
Could not create the Java virtual machine
Anyway that I could run my app?

And I must add. If I am running it from an IDE (eclipse) instead of cmd, is there someway to do it?

fix the bug in your application that causes it to require inordinate amounts of memory.
I can guarantee you that whatever amount you feed it with you'll run out eventually unless you fix that bug.

Your OS/CPU architecture limits the maximum heap size you can allocate for your JVM process. Read this.

The setting for heap size depends on the IDE which you are using but for eclipse, see this.

Thanks alot, allocating more memory somehow got it running completely. At the same time I tweaked it a bit, so that less memory is consumed.

This question has already been answered. Start a new discussion instead.