JUnit 测试内存不足——如何增加堆大小?
我正在运行 Junit 测试,该测试抛出 OutOfMemory 异常。 测试在 NetBeans 6.9.X 内部启动。当我分析它时 意识到Heap maxSize是64M。我想增加这个 但我找不到如何做到这一点。
我已经尝试右键单击项目 -> 属性 -> 运行 在虚拟机选项下我设置了 -Xms300M 但这不起作用。
有什么提示吗?
提前致谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
来自 http://wiki.gephi.org/index.php/NetBeans_Tips#How_to_increase_Heap_Size_for_JUnit_test
编辑您的project.properties 文件并添加以下行:
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:
您还可以通过为操作系统设置此环境变量来增加所有虚拟机的最大大小:
You can also increase the max size for all VMs by setting this environment variable for your OS:
你是否调整了-Xmx以及-Xms
-Xms300m会强制java使用不少于300m,而-Xmx300m会让jvm使用不超过300m
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
您可以尝试一下这个,看看是否有帮助:
You can try this and see if it helps:
虽然 Java 程序通常不会泄漏通常意义上的内存,但列表和映射等集合中可能会不必要地占用内存。使用分析器查看内存的使用情况,您可能会发现优化的机会。
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.