views:

4317

answers:

5

Hi,

while running junit tests I always seem to run into the above error. I have monitored eclipse with JConsole and heap memory peaks at about 150MB and yet I have set heap memory to 1GB?

I am using the following argumments 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? Its only when running junit tests

thanks

+10  A: 

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.

Thijs Wouters
+2  A: 

You probably have a memory leak in your JUnit tests. A common gotcha is this: Junit will create a new instance of a TestCase class for every test method in it And all instance variables will be kept around until JUnit terminates. That means: if you have a TestCase class with 50 test methods and an instance variable that is initialized with a 1MB object graph in your setUp() method, then that TestCase class will require 50MB heap space.

Michael Borgwardt
A: 

I've just released a plugin for Eclipse that will automatically set the heap size on JUnit launchers for you. You can get it from http://code.google.com/p/junitlaunchfixer/ It works with Eclipse Europa, Ganymede and Galileo.

Joey Gibson
A: 

I found the solution to my problem - it may help others ;) When I was increasing the heap size I was increasing the heap size of eclipse application, not of my program (which I executed through eclipse) What I had to do is modify the execution commands before running my program.

Ana
+1  A: 

Further to @Thijs Wouters response, to fix this issue in eclipse I did the following:

  • Added a new Run configuration under JUnit (Run>Run configuration>JUnit>New)
  • Within the arguments tab set VM arguments to "-Xms64m -Xmx256m" or higher if needs be
Nigel_V_Thomas