问题描述
我的应用程序目前消耗了大量内存,因为它正在运行物理模拟。问题是始终如一,在第51次模拟中,java会抛出一个错误,通常是因为堆空间内存不足(我的程序最终运行了数千次模拟)。
My application currently consumes quite a lot of memory because it is running physics simulations. The issue is that consistently, at the 51st simulation, java will throw an error usually because of a heap space out of memory (my program eventually runs thousands of simulations).
无论如何我不仅可以增加堆空间而是修改程序,以便在每次运行后清空堆空间,这样我就可以运行任意数量的模拟?
Is there anyway I can not just increase the heap space but modify my program so that the heap space is cleared after every run so that I can run an arbitrary number of simulations?
谢谢
-edit -
-edit-
多谢你们。事实证明,模拟器软件在每次运行后都没有清除信息,我将这些运行全部存储在一个arraylist中。
Thanks guys. Turns out the simulator software wasn't clearing the information after every run and I had those runs all stored in an arraylist.
推荐答案
由于在Java虚拟机启动时分配了堆,因此无法以编程方式动态增加堆。
There is no way to dynamically increase the heap programatically since the heap is allocated when the Java Virtual Machine is started.
但是,您可以使用此命令
However, you can use this command
java -Xmx1024M YourClass
将内存设置为1024
to set the memory to 1024
或者,您可以设置最小最大值
or, you can set a min max
java -Xms256m -Xmx1024m YourClassNameHere
这篇关于Java堆空间内存不足的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!