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

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

问题描述

我的代码正在执行以下操作:

My code is doing things like this:

for(SomeObject so : someObjects)
{
  Blah b = so;
  NewObject n = dao.GetNO(b.23);
}

即它会在每次迭代的for循环内创建一个新变量.

i.e. it is creating a new variable inside the for loop on each iteration.

这可能是内存不足问题的原因吗?

Could this be the cause of the out of memory issue?

Netbeans报告的错误:

The error reported by Netbeans:

Caused by: java.lang.OutOfMemoryError: Java heap space
        at java.lang.StringCoding$StringDecoder.decode(StringCoding.java:133)
        at java.lang.StringCoding.decode(StringCoding.java:173)
        at java.lang.String.<init>(String.java:443)
        at java.lang.String.<init>(String.java:515)
        at com.gargoylesoftware.htmlunit.WebResponseImpl.getContentAsString(WebResponseImpl.java:215)
        at com.gargoylesoftware.htmlunit.WebResponseImpl.getContentAsString(WebResponseImpl.java:205)

更新 这是一个Java控制台应用程序,整个应用程序基本上都在forloop中运行.

Upate This is a java console application, and the entire app runs a in forloop basically.

推荐答案

您是否在使用Java 5或更高版本或旧版JVM之一运行?您可以通过使用-XX:+ HeapDumpOnOutOfMemory来武装Java命令行,或者使用 Eclipse MAT 工具打开转储并查看对象图以查看其持有者到程序中的对象上. MAT可以查看那些在对象图中起主导作用的对象-这样就可以非常清楚地知道泄漏的对象是什么.查看堆栈跟踪无济于事,并且可能会产生误导,因为程序一个位置的泄漏可能导致其他位置的分配失败.

Are you running with Java 5 or greater, or one of the legacy JVM's? You can try to track down the cause of your OOM by arming your Java command line with -XX:+HeapDumpOnOutOfMemory or attaching to your process with JConsole and requesting a heap dump. You can then use the Eclipse MAT tool to open the dump and view the object graph to see whose holding onto the objects in your program. MAT has a view to see those objects that dominate the object graph - so it becomes extremely clear what exactly is leaking. Looking at the stack trace is not helpful, and can be misleading because a leak in one location of the program can cause a failed allocation somewhere else.

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

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