views:

1053

answers:

6

In my project I often encounter Java heap space errors, i.e., there isn't enough space to run the program any more. Is there any way I can increase virtual memory?

I am not using the command-line. I am using Net Beans.

A: 

Java -X, read about java -Xms and -Xmx

Fredrik
btw, you can use the format "java -Xmx1G", makes the command line a bit shorter than to specify the exact number of bytes.
Fredrik
i am not using command-line for a desktop application
Arunachalam
Same java, same arguments. your "desktop" application is very likely to have a command that starts it.
Fredrik
so how to use command line arguments in a desktop application
Arunachalam
Depends on how you start your app and on you operating system. Typically you have an icon or something that hides a path and a command line but as Dennis points out there are other alternatives as well (like JNLP). I suggest you create another question for that.
Fredrik
Btw, the "From netbeans" part wasn't in your question when I answered it so it was hard to consider. I am not using netbeans but it is still a matter of java using a jvm that needs to be started with the -Xms and -Xmx to get a bigger heap.
Fredrik
A: 

Use the command line arguments when invoking JVm as,

java -Xms -Xmx

Sandy
A: 

Running JAR directly is on longer suggested (from Sun) (someone may disagree).

You are suggested to use WebStart/JNLP, applet, or exe/batch wrapper that you can control the startup behaviour of the JVM.

The another way you can do is that implement your own wrapper in Java. i.e. fork the real java.exe with -Xmx in your main() function.

Dennis Cheung
When you say "fock the real java.exe" I think you mean "fork the real java.exe", yes?
Eddie
+2  A: 

In NetBeans, you can add command line options using the Properties of the Project, the Run option. There is an option for the JVM command line there. Look at the -Xms and -Xmx options.

This works for JRuby projects as well, incidentally.

MatthieuF
+1  A: 

Under Netbeans you can set the VM options for a project, in the project properties. Under Properties > Run the last box should be VM Options. Netbeans will use those when running the app.

Philip T.
A: 

My computer is Lenovo Core2Due Processor. When i tried to send emails from my website http://www.moneyinhands.com then i faced trouble about low virtual memory. Please suggest me that how i increase my system virtual memory to i work easily without any difficulty.

sanjay kumar