堆空间不足 [英] Heap space out of memory

查看:87
本文介绍了堆空间不足的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序当前正在运行物理模拟,因此会占用大量内存.问题在于,在第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?

编辑:谢谢.事实证明,模拟器软件并没有在每次运行后清除信息,而我将那些运行都存储在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

这篇关于堆空间不足的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆