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

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

问题描述

我的应用程序当前消耗了大量内存,因为它正在运行物理模拟.问题在于,在第 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

或者,您可以设置最小最大值

or, you can set a min max

java -Xms256m -Xmx1024m YourClassNameHere

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

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