Heap space out of memory

前端 未结 9 1712
梦如初夏
梦如初夏 2020-11-27 04:33

My application currently consumes quite a lot of memory because it is running physics simulations. The issue is that consistently, at the 51st simulation, Java will throw an

相关标签:
9条回答
  • 2020-11-27 05:15

    I would like to add that this problem is similar to common Java memory leaks.

    When the JVM garbage collector is unable to clear the "waste" memory of your Java / Java EE application over time, OutOfMemoryError: Java heap space will be the outcome.

    It is important to perform a proper diagnostic first:

    • Enable verbose:gc. This will allow you to understand the memory growing pattern over time.
    • Generate and analyze a JVM Heap Dump. This will allow you to understand your application memory footprint and pinpoint the source of the memory leak(s).
    • You can also use Java profilers and runtime memory leak analyzer such as Plumbr as well to help you with this task.
    0 讨论(0)
  • 2020-11-27 05:23

    There is no way to dynamically increase the heap programatically since the heap is allocated when the Java Virtual Machine is started.

    However, you can use this command

    java -Xmx1024M YourClass
    

    to set the memory to 1024

    or, you can set a min max

    java -Xms256m -Xmx1024m YourClassNameHere
    
    0 讨论(0)
  • 2020-11-27 05:25

    Are you keeping references to variables that you no longer need (e.g. data from the previous simulations)? If so, you have a memory leak. You just need to find where that is happening and make sure that you remove the references to the variables when they are no longer needed (this would automatically happen if they go out of scope).

    If you actually need all that data from previous simulations in memory, you need to increase the heap size or change your algorithm.

    0 讨论(0)
提交回复
热议问题