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

问题描述

执行多线程程序时出现以下错误

I am getting the following error on execution of a multi-threading program

java.lang.OutOfMemoryError: Java heap space

其中一个主题出现上述错误。

The above error occured in one of the threads.


  1. 据我所知,堆空间仅由实例变量占用。如果这是正确的,那么为什么在运行正常之后出现这个错误,因为实例变量的空间是在创建对象时分配的。

  1. Upto my knowledge, Heap space is occupied by instance variables only. If this is correct, then why this error occurred after running fine for sometime as space for instance variables are alloted at the time of object creation.

有没有增加堆空间的方法?

Is there any way to increase the heap space?

我应该对程序进行哪些更改,以便减少堆空间?

What changes should I made to my program so that It will grab less heap space?


推荐答案

如果你想增加堆空间,你可以使用 java -Xms< ;初始堆大小>命令行上的-Xmx<最大堆大小> 。默认情况下,这些值基于JRE版本和系统配置。您可以在。

If you want to increase your heap space, you can use java -Xms<initial heap size> -Xmx<maximum heap size> on the command line. By default, the values are based on the JRE version and system configuration. You can find out more about the VM options on the Java website.

但是,我建议您分析您的应用程序,以找出您的堆大小被吃掉的原因。 NetBeans随附了。我相信它使用引擎盖下。使用分析器,您可以尝试查找正在创建许多对象的位置,对象何时进行垃圾回收等等。

However, I would recommend profiling your application to find out why your heap size is being eaten. NetBeans has a very good profiler included with it. I believe it uses the jvisualvm under the hood. With a profiler, you can try to find where many objects are being created, when objects get garbage collected, and more.

这篇关于java.lang.OutOfMemoryError:Java堆空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 06:09