Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are possible reasons to cause running out of heap space and Are there best practice to avoid it? [closed]

Tags:

java

scala

Hi two questions if I can learn?

  1. What are possible reasons to cause running out of heap space in Scala or Java?
  2. Are there best practice to avoid it?
like image 862
monica Avatar asked Sep 05 '25 23:09

monica


1 Answers

When you start a Java process, it sets a default maxHeapMemory, which is the maximum heap memory that can be used by that process. You can pass a command-line argument to increase that, but depending on your application's memory usage, it still may not enough. Memory leaks is another problem that can eat up your memory (not releasing it for garbage collection) possibly causing out of memory issues. Setting the heap memory allocated in the beginning and maximum allowed heap memory depends on your application, its memory usage, you can judge, test and profile your application (for memory usage) for that.

like image 95
Swapnil Avatar answered Sep 09 '25 20:09

Swapnil