Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Added Out of Memory cause of too much space allocated for Heap

...

  • A servlet trying to load a several GBytes file into memory will surely kill the server. These kind of errors must be considered a simple bug in our program.
  • Wiki Markup
    To compensate for the data your servlet tries to load, you increase the heap size so that there is no room to create the stack size for the threads that need to be created.  Each thread takes 2M and in some OS's (like Debian Sarge) is not reducible with the -Xss parameter. \[http://goobsoft.homeip.net/Wiki.jsp?page=JavaDebianTuning 1\]  Rule of Thumb, use no more than 1G for heap space in a 32-bit web application.
  • Deep recursive algorithms can also lead to Out Of Memory problems. In this case, the only fixes are increasing the thread stack size (-Xss), or refactoring the algorithms to reduce the depth, or the local data size per call.
  • A webapp that uses lots of libraries with many dependencies, or a server maintaining lots of webapps could exhauste the JVM PermGen space. This space is where the VM stores the classes and methods data. In those cases, the fix is to increase this size. The Sun VM has the flag -XX:MaxPermSize that allows to set its size (the default value is 64M)
  • Hard references to classes can prevent the garbage collector from reclaiming the memory allocated for them when a ClassLoader is discarded. This will occur on JSP recompilations, and webapps reloads. If these operations are common in a webapp having these kinds of problems, it will be a matter of time, until the PermGen space gets full and an Out Of Memory is thrown.

...