Java root cause java.lang.OutOfMemoryError error
Solution 1
Here's what the Tomcat guys have to say:
An Out Of Memory can be thrown by several causes:
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.
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. The memory required by each thread will vary by OS but can be as high as 2M by default and in some OS's (like Debian Sarge) is not reducible with the
-Xss
parameter. 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.
Source: Tomcat Wiki: OutOfMemory
Solution 2
Well... who really caused the out of memory error?
If you ate 8 slices of pizza and you are full, is it the last slice that caused the out of stomach error?
Admin
Updated on June 14, 2022Comments
-
Admin almost 2 years
I am new to Java and given the task to fix a bug and the issue is as follows. It would be really great if you give suggestions/ideas what is this issue and how can I fix this.:
HTTP Status 500 - -------------------------------------------------------------------------------- type Exception report message description The server encountered an internal error () that prevented it from fulfilling this request. exception org.apache.jasper.JasperException org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:453) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:375) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264) javax.servlet.http.HttpServlet.service(HttpServlet.java:802) org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:368) root cause javax.servlet.ServletException org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:858) org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:791) org.apache.jsp.CustMaint.Jsp.ProfProfileDetails_jsp._jspService(ProfProfileDetails_jsp.java:4016) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97) javax.servlet.http.HttpServlet.service(HttpServlet.java:802) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264) javax.servlet.http.HttpServlet.service(HttpServlet.java:802) org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:368) root cause java.lang.OutOfMemoryError note The full stack trace of the root cause is available in the Apache Tomcat/5.5.17 logs. -------------------------------------------------------------------------------- Apache Tomcat/5.5.17
-
bestsss about 13 years
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.
That causes StackOverflow Error, both are VirtualMachineError but it's beyond the point -
bestsss about 13 yearsAnd using direct buffers can cause OOM, just as fine.
-
BalusC about 13 years@bestsss: or
OutOfMemoryError
when the stack isn't overflow yet, but memory is due to the expensive job during each recursion step. -
bestsss about 13 years@BalusC, - read again: "-Xss" stack size, anything to do w/ heap? In this case any ideas to reduce depth, anything at all of the suggestions would be absolutely out of place. Converting the recursion to iteration will cost even more heap! Tomcat Wiki is plain wrong.
-
Nishant about 13 yearslol! can't really up-vote. But if there is a "like" button, I would surely click for this answer.