Java Out Of Heap Space Error

2019-07-16 12:50发布

I'm running a very long process via an Ant script, I allowed the following heap but it still give me the error.

set ANT_OPTS=-Xms1024M -Xmx2024M -XX:MaxPermSize=512M

标签: java ant
3条回答
Anthone
2楼-- · 2019-07-16 13:16

It seems strange to me that you are using more 2G to perform a build (although it's clearly possible) so I'll make some silly questions just to help you thinking on your problem:

  • Are you really sure that the ANT_OPTS is correctly set?
  • Are you launching the script from command line or from an IDE?
  • Which OS are you using?
  • How much physical memory have you got in your box?
  • Are you using any plugin or tool triggered by the build?
  • Are you launching test during the build? Are you forking during tests?
查看更多
地球回转人心会变
3楼-- · 2019-07-16 13:22

This means that your code really is trying to use more than 2G of memory. Use jprofiler, or yourkit, or the JVM's built-in tools, to find out what it's doing and reduce the memory usage.

Further, if on a 32-bit machine, you can't necessarily get a full 2G.

查看更多
我想做一个坏孩纸
4楼-- · 2019-07-16 13:37

You can also enable garbage collection logging (details here) and have a look at why your Heapspace is increasing so much. It could be a memory leak. Ofcourse, JProfiler will also allow you to do the same. Eclipse 3.4 and above have a profiler built in which you can attach to the JVM where your program is running if you do not wish to use JProfiler.

查看更多
登录 后发表回答