JUnit test runs out of memory -- how to increase heap size?
Asked Answered
M

5

11

I am running a Junit test which throws an exception OutOfMemory. The test is started inside NetBeans 6.9.X. When profiling it I've realized that the Heap maxSize is 64M. I would like to increment this but I couldn't find how to do this.

I already tried right click at the project ->properties ->Run and under the VM options I've set -Xms300M but this didn't work.

Any hint?

Thanks in advance.

Mendelsohn answered 15/9, 2011 at 16:31 Comment(3)
Try changing/adding the Xms parameter netbeans_default_options in etc/netbeans.confRundlet
Thanks, already tried and it is not working. It crashes when the heap reaches 64M. I've set this netbeans_default_options = "-J-Xms384m -J-Xmx512m -J-XX:PermSize=32m -J-XX:MaxPermSize=96m -J-Xverify:none -XX:+HeapDumpOnOutOfMemory"Mendelsohn
Post your stack trace please.Reluctant
A
7

From http://wiki.gephi.org/index.php/NetBeans_Tips#How_to_increase_Heap_Size_for_JUnit_test

Edit your project.properties file and add the line:

test.run.args=-Xms128m -Xmx1400m
Annelleannemarie answered 15/9, 2011 at 16:42 Comment(3)
Unfortunately that link is broken now.Languorous
Here's an archived version of that page: web.archive.org/web/20130314101004/http://wiki.gephi.org/…Annelleannemarie
Does that still apply to Netbeans 8? Current Netbeans doc has no reference to that file that I could find, and if I put it in the prescribed place, nothing happens, the test still runs with default memory.Languorous
P
5

You can also increase the max size for all VMs by setting this environment variable for your OS:

 _JAVA_OPTIONS=-Xmx300m
Pepillo answered 15/9, 2011 at 16:43 Comment(1)
I didn't know that. Thats cool. So, on windows you could do: SET /P _JAVA_OPTIONS=-Xmx300M ? Awesome.Reluctant
C
3

Have you adjusted -Xmx as well as -Xms

-Xms300m will force java using no less 300m, and -Xmx300m will let jvm use no more than 300m

Clannish answered 15/9, 2011 at 16:36 Comment(0)
R
1

You can try this and see if it helps:

-XX:MaxPermSize=128m
Reluctant answered 15/9, 2011 at 16:35 Comment(3)
No. This is not about permgen. He is running out of total heap.Nobie
No, thats incorrect. He didn't he ran out of heap. He said "OutOfMemory" (in general) and I know that the PermGen argument fixes a certain type of OOME.Reluctant
True. I am curious though to know why you think this this not a total heap problem but rather specifically permgen problem.Nobie
N
0

While Java program usually don't leak memory in usual sense there could be memory unnecessarily occupied in collections like lists and maps. Use a profiler to see where the memory is being used, you will likely find opportunities for optimization.

Nobie answered 15/9, 2011 at 16:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.