0

I know there has been already many discussions about this issue on SO but none of them solve my problem. I have a file test.txt and I want to do some sentiment analysis on it. The format of the input file in one sentence per line. And I run the tool with following command:

java  -cp "../*" -mx1g edu.stanford.nlp.sentiment.SentimentPipeline -file test.txt 

And it began to run and print the content of my file in a strange way. After a while, it throws this error:

Exception in thread "main" java.lang.OutOfMemoryError: Java heap space

I also tried:

java -Xms1024m -Xmx2048m -cp "../*" -mx1g edu.stanford.nlp.sentiment.SentimentPipeline -file test.txt

But it still didn't work. BTW, I run the tool in command line instead of eclipse. So I think it is not about eclipse. Could you please help me with this issue? Thanks in advance!

southdoor
  • 431
  • 1
  • 8
  • 22

2 Answers2

0

You can change -mx1g to -mx4g in your command

Try with the following command:

java -Xms1024m -Xmx2048m -cp "../*" -mx4g edu.stanford.nlp.sentiment.SentimentPipeline -file test.txt

Suggestion#1:

You can permanently increase -Xms and -Xmx size

Windows:

SET _JAVA_OPTIONS = -Xms1024m -Xmx2048m

Linux:

export _JAVA_OPTIONS="-Xms1024m -Xmx2048m"

after that you can run the command simply

java -cp "../*" -mx4g edu.stanford.nlp.sentiment.SentimentPipeline -file test.txt

Hope it will solve your issue. If it not solve your problem, then increase the -Xmx size to -Xmx6g

Suggestion#2:

You can use Java8. They use metaspace for heap. So, no heap space error will be occured there.

Resource Link:

how to increase java heap memory permanently?

UPDATE:

Please check with following commands

java -cp "../*" -Xmx4g edu.stanford.nlp.pipeline.StanfordCoreNLPClient -annotators tokenize,ssplit,pos,lemma,ner,parse,dcoref -file test.txt

or you can use -threads 1 in the command to make it single-threaded.

Resource Link:

  1. Stanford NLP - OpenIE out of memory when processing list of files
  2. CoreNLP Server Conf
Community
  • 1
  • 1
SkyWalker
  • 28,384
  • 14
  • 74
  • 132
  • Thanks for your answer. But it doesn't solve my problem. And I said I didn't use Eclipse. So my question is totally different from that one. Please remove the duplicate. – southdoor Nov 27 '16 at 18:27
  • Would you please check using `java -Xmx6144M -d64` @southdoor – SkyWalker Nov 27 '16 at 18:32
  • Thanks for your update. Do you mean JDK8? Sorry I have used Java before. Please forgive my stupid question.. – southdoor Nov 27 '16 at 19:05
  • @southdoor yes JDK8 – SkyWalker Nov 27 '16 at 19:17
  • But when I run `java -version`, I got `java version "1.8.0_111" Java(TM) SE Runtime Environment (build 1.8.0_111-b14) Java HotSpot(TM) 64-Bit Server VM (build 25.111-b14, mixed mode)`. Does it mean the version is already 8? – southdoor Nov 27 '16 at 19:42
  • @southdoor I have updated the answer. Would you please check and let me know the feedback. – SkyWalker Nov 28 '16 at 16:20
0

It means there is insufficient space to allocate the new object. Like in this case the garbage collector can't make space to accommodate a new object.