Getting Out Of Memory: Java heap space, but while viewing heap space it max uses 50 MB

狂风中的少年 提交于 2019-12-11 04:54:39

问题


I'm using ASANT to run a xml file which points to a NARS.jar file. (i do not have the project file of the NARS.jar)

I'm getting "java.lang.OutOfMemoryError: Java heap space.

I used VisualVM to look at the heap while running the NARS.jar, and it says that it max uses 50 MB of the heapspace.

I've set the initial and max size of heapspace to 512 MB.

Does anyone have an ide of what could be wrong?

I got 1 GB physical Memory and created a 5 GB pagefile (for test purpose).

Thanks in advance.


回答1:


Your app may be trying to allocate memory that exceeds your 512m limit, thus you see an outofmemory error even though only 50m is being used. To test this, I would set:

-Xms512m -Xmx1024m

And see what happens. I would also try a smaller test file, say 1g. Keep reducing the file size until you stop seeing the error. If you succeed, then the trouble is that what you're trying to do and the way you're trying to do it takes too much memory. Time to look for an alternate approach.




回答2:


Are you forking the process when running the NARS.jar file? Setting ANT_OPTS will only have effect on the VM running the ant system. If you use the java task to start/fork an additional VM process, the ANT_OPTS settings will not be inherited.

If this is the case, set either fork="false" in the java task (if you are not using any other options, which require fork to be enabled), or set maxmemory="512m".




回答3:


XML files are notorious memory hogs since the DOM representation can often require ten times their size on disk.

My guess is that this is where you hit the limit. Is there a stack trace with the out of memory exception?



来源:https://stackoverflow.com/questions/2410277/getting-out-of-memory-java-heap-space-but-while-viewing-heap-space-it-max-uses

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!