How to increase the java heap size in netbeans?

Noopur Phalak picture Noopur Phalak · Mar 17, 2013 · Viewed 67.1k times · Source

I am trying to build a lexicon trie of almost 110000 words in java in netbeans. My code is running fine but it gives an Exception as follows:

   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 someone could help me with increasing the java heap space in netbeans.

Answer

1218985 picture 1218985 · Mar 17, 2013

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

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

Example: Putting -Xmx512m in the "VM Options" text box gives 512Mb maximum heap size to your Java program.