java.lang.OutOfMemoryError:Java 堆空间 [英] java.lang.OutOfMemoryError: Java heap space

查看:42
本文介绍了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 版本和系统配置.您可以在 Java 网站上找到更多关于 VM 选项的信息.

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 包含一个非常好的分析器.我相信它使用 jvisualvm 在引擎盖下.使用分析器,您可以尝试找出许多对象的创建位置、对象何时被垃圾回收等.

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 堆空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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