简体   繁体   中英

How can I correct a “Java heap space - Out of Memory” error

I'm currently running my system against a rather large dataset and am getting the error. 'Out of memory. Java Heap Space'.

Is there anyway to get around this or is it just a case of the dataset is too large and can't be used?

In general, you can either

  • give it more memory eg increase the maximum heap size, but don't give it more than about 90% of main memory. BTW the default is 25% of main memory up to 32GB.
  • optimise the code so that it uses less memory, eg use a memory profiler. You can use a more efficient data structure or load portions of data into memory at a time.
  • break up the data so it own works on a portion at a time.

If it's not the dataset that's eating up memory, it could be that you are not freeing up objects once they are inactive.

This is typically due to keeping references to very large objects or to lots objects laying around long after they are no longer needed. This is most likely references that are static variables, but it can also be references to large temporary variables (eg, large StringBuilder objects) within methods that are still active.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM