Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does heap space run out only when running JUnit tests?

When running JUnit tests, I always seem to run into this error:

eclipse outOfMemoryError: heap space

I have monitored Eclipse with JConsole and heap memory peaks at about 150MB. I have set heap memory to 1GB.

I am using the following arguments when starting Eclipse:

 -vm "C:\Program Files\Java\jre1.5.0_08\bin\javaw.exe" -vmargs -Xmx1024M -XX:MaxPermSize=128M -Dcom.sun.management.jmxremote.port=8999 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false 

Does anyone know what may be causing this issue? It happens only when running JUnit tests.

like image 873
smauel Avatar asked Mar 25 '09 11:03

smauel


People also ask

How do I fix out of memory error in Junit?

Junit tests are run in a different vm as the Ee IDE. So it is that vm that is out of memory and not the Ee one. You can change the settings of the test vm in the run configurations of the test. You go to the run configurations and then under arguments, you can set the vm arguments.

How do I stop Java heap exhaustion?

If the Java heap is being exhausted, and increasing the Java heap size does not solve the problem, the next stage is to examine the objects that are on the heap, and look for suspect data structures that are referencing large numbers of Java objects that should have been released.

How do I fix Java out of memory error heap space?

OutOfMemoryError: Java heap space. 1) An easy way to solve OutOfMemoryError in java is to increase the maximum heap size by using JVM options "-Xmx512M", this will immediately solve your OutOfMemoryError.

How do I fix Java heap space in eclipse?

Temporary fix – Increase the heap size On the Eclipse menu, clicks Run -> Run Configurations.. , select the Java application we want to run, click on the Arguments tab, VM arguments section, and adjust a better Java initial maximum heap size.


1 Answers

Junit tests are run in a different vm as the Eclipse IDE. So it is that vm that is out of memory and not the Eclipse one.
You can change the settings of the test vm in the run configurations of the test.
You go to the run configurations and then under arguments, you can set the vm arguments.

like image 95
Thijs Wouters Avatar answered Sep 24 '22 16:09

Thijs Wouters