How to increase java heap size in netbeans?

I am trying to create a lexicon trie of almost 110,000 words in java in netbeans. My code works fine, but it gives an exception like this:

   Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at java.util.Arrays.copyOfRange(Arrays.java:3209)
at java.lang.String.<init>(String.java:215)
at java.nio.HeapCharBuffer.toString(HeapCharBuffer.java:542)
at java.nio.CharBuffer.toString(CharBuffer.java:1157)
at java.util.regex.Matcher.toMatchResult(Matcher.java:232)
at java.util.Scanner.match(Scanner.java:1270)
at java.util.Scanner.nextLine(Scanner.java:1517)
at lexiconbuild.model.Lexicon.<init>(Lexicon.java:29)
at lexiconbuild.model.LexiconBuild.main(LexiconBuild.java:17)
Java Result: 1

      

I was wondering if anyone can help me with increasing java heap space in netbeans.

+28


source to share


3 answers


You can set it in NetBeans in project properties -> Run -> VM options

  • Right-click on your project " Properties "
  • Select the Run category .
  • Enter your arguments ( -Xmx512m ) in the VM Options text box .


Example. Putting -Xmx512m in the VM Options text box gives a maximum heap size of 512MB for your Java program.

+47


source


if you want to change it for netbeans you can change it from this file:

netbeans.conf 

      

you will find it in netbeans folder under / etc

and there are two parameters for the heap

Xms is the initial size of the heap.

Xmx - max java heap size



using the default you just need to add it there and try to add both of them.

and also don't forget to add them to netbeans_default_options when XMX changes

-J-XX:+UseConcMarkSweepGC -J-XX:+CMSClassUnloadingEnabled -J-XX:+CMSPermGenSweepingEnabled

      

so netbeans_default_options will be something like this:

netbeans_default_options="-J-client -J-Xss2m -J-Xms512m -J-Xmx1024m -J-XX:PermSize=256m -J-Dapple.laf.useScreenMenuBar=true -J-Dapple.awt.graphics.UseQuartz=true -J-Dsun.java2d.noddraw=true -J-Dsun.zip.disableMemoryMapping=true -J-XX:+UseConcMarkSweepGC -J-XX:+CMSClassUnloadingEnabled -J-XX:+CMSPermGenSweepingEnabled"

      

+29


source


In the launch configuration, you must set the Java VM option -Xmx512m

or other that limits the maximum Java VM size to 512M. You can always experiment with other values. You are only limited by the physical memory used by the OS.

+3


source







All Articles