Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

increasing heap size in netbeans.conf file

I was reading in netbeans 6, you don't have to set the maximum heap size, it will just look at your computer for that information.

My system has 8 gigs of ram, but my application only has 64mb to play with and it is running out of memory.

I did a:

System.out.println(Runtime.getRuntime().maxMemory());

And it is 66 650 112 bytes (63.5625 megabytes).

my netbeans.config:

-J-Xss2m -J-Xms32m -J-XX:PermSize=32m -J-XX:MaxPermSize=200m

I tried to change these numbers, but then netbeans failed to load (JVM error).

How can I increase the maximum size to 1 GB?

like image 911
mrblah Avatar asked Nov 29 '22 19:11

mrblah


1 Answers

EDIT: responding to the comment

If your application has a specific need for heap space, you can set the virtual machine parameters that you would like it to use. For example, I have a default maximum heap size that I use in the default run configuration. I also have larger maximums for run configurations where I know that I will be processing more data.

You can access the run configurations several ways:

  1. Right click the project (under Projects) and select "Properties." Click "Run" and notice the "VM options" text field that appears on the right. If you add "-Xmx1024" to that field, you will allow the heap to grow to a maximum size of 1024 megabytes.
  2. You can also customize the run configurations directly from the combo box in the "Run" toolbar. If you click the combo box, you'll see that the last choice is "Customize." This will bring up the same dialog box.

It is important to note that setting the maximum heap size does not immediately allocate that much memory. With my current work, I prefer to allow the heap to grow up to the maximum if necessary but also, to be a good neighbor with other services on the machine, I allow it to keep a small heap if things fit. You can, however, specify that heap size should start at the maximum possible size by using the -Xms option.

For example, if you set the virtual machine options to "-Xms1024m -Xmx1024m", the application will grab the entire gig of memory on startup and hold it for the entire run.

End EDIT

If you'd like to ensure that Netbeans always has enough heap space, you can do this one of two easy ways. One is to modify the netbeans.conf file. In mine, the original line reads like so:

netbeans_default_options="-J-client -J-Xverify:none -J-Xss2m -J-Xms32m -J-XX:PermSize=32m -J-XX:MaxPermSize=200m -J-Dapple.laf.useScreenMenuBar=true -J-Dsun.java2d.noddraw=true"

If you would like to give Netbeans up to one gig of RAM to play with, you can change the line to read like so:

netbeans_default_options="-J-client -J-Xverify:none -J-Xmx1024m -J-Xss2m -J-Xms32m -J-XX:PermSize=32m -J-XX:MaxPermSize=200m -J-Dapple.laf.useScreenMenuBar=true -J-Dsun.java2d.noddraw=true"

where the "-J-Xmx1024m" argument will allow the heap to grow up to a size of 1024 meg.

However, it's even easier to set the max heap for Netbeans at runtime from a launcher or shortcut. On my machine, I have a launcher that passes the max heap in directly without changing the configuration file:

/usr/local/netbeans-6.8/bin/netbeans -J-Xmx1024m

Feel free to use whichever is most convenient for you.

like image 64
Bob Cross Avatar answered Dec 05 '22 04:12

Bob Cross