java.lang.OutOfMemoryError: Java heap space with NetBeans
Solution 1
Changing the heap size in netbeans.conf only changes the heap for NetBeans itself, not for applications run through NetBeans.
The correct way is to right-click on the project and select "Properties" and then "Run"; there you can set the VM options appropriately (-Xmx256m
, for instance). It should look something like this:
(Thanks to VonC for finding this picture.)
Solution 2
Stop Tomcat server, set environment variable CATALINA_OPTS, and then restart Tomcat. Look at the file tomcat-install/bin/catalina.sh
or catalina.bat
for how this variable is used. For example,
set CATALINA_OPTS="-Xms512m -Xmx512m" (Windows)export CATALINA_OPTS="-Xms512m -Xmx512m" (ksh/bash)setenv CATALINA_OPTS "-Xms512m -Xmx512m" (tcsh/csh)
In catalina.bat
or catallina.sh
, you may have noticed CATALINA_OPTS, JAVA_OPTS, or both can be used to specify Tomcat JVM options.
What is the difference between CATALINA_OPTS and JAVA_OPTS?
The name CATALINA_OPTS is specific for Tomcat servlet container, whereas JAVA_OPTS may be used by other java applications (e.g., JBoss). Since environment variables are shared by all applications, we don't want Tomcat to inadvertently pick up the JVM options intended for other apps. I prefer to use CATALINA_OPTS.
How to set java heap size in JBoss?
Stop JBoss server, edit $JBOSS_HOME/bin/run.conf, and then restart JBoss server. You can change the line with JAVA_OPTS to something like:
JAVA_OPTS="-server -Xms128m -Xmx128m"
How to set java heap size in Eclipse? You have 2 options:
-
Edit eclipse-home/eclipse.ini to be something like the following and restart Eclipse.
-vmargs-Xms64m-Xmx256m
-
Or, you can just run eclipse command with additional options at the very end. Anything after -vmargs will be treated as JVM options and passed directly to the JVM. JVM options specified in the command line this way will always override those in eclipse.ini. For example,
eclipse -vmargs -Xms64m -Xmx256m
How to set java heap size in NetBeans?
Exit NetBeans, edit the file netbeans-install/etc/netbeans.conf. For example,
netbeans_default_options="-J-Xms512m -J-Xmx512m -J-XX:PermSize=32m -J-XX:MaxPermSize=128m -J-Xverify:none
How to set java heap size in Apache Ant?
Set environment variable ANT_OPTS. Look at the file $ANT_HOME/bin/ant
or %ANT_HOME%\bin\ant.bat
, for how this variable is used by Ant runtime.
set ANT_OPTS="-Xms512m -Xmx512m" (Windows)export ANT_OPTS="-Xms512m -Xmx512m" (ksh/bash)setenv ANT_OPTS "-Xms512m -Xmx512m" (tcsh/csh)
Solution 3
If you increase the virtual memory of your Tomcat server then it will be OK.
Steps:
- In NB go through the windows menu and add Services
- You will find Tomcat in the services. Right click on Tomcat server and select Properties
- Go to the platform in the properties and write
-Xms512m
in VM options field
Solution 4
I'm guessing that increasing the memory won't fix the problem. What is that MonitorFilter doing? What's eating up all that memory?
Your best bet is to figure that out. If this is a web app, see if you can turn off that filter and run without it. If you have success, you know that the MonitorFilter is causing your to fail.
Solution 5
This has nothing to do with NetBeans (well, perhaps), rather it has to do with Tomcat. Tomcat is the process that is running out of heap, not NetBeans. Track down the startup process for your Tomcat. If it's bundled with NB, then Tomcat is buried within the NB installation, check for an "enterpriseN" directory, N being a number, Tomcat is probably in there and it's a rather generic distribution of it.
As to why the monitor is run OOM, that's hard to say, it's a pretty simple process when you think about it. You can also try disabling HTTP monitoring to see if it's a problem with the Monitoring itself or something with your application.
trincot
I am an IT project manager at an administration, and worked as software engineer before. Here are some of the answers I found most useful or fun (not necessarily accepted, nor highest voted): Algorithm - Fastest way to sort an array only using these blackbox functions? Algorithm - Minimum number of steps to reduce number to 1 Algorithm - Solve a maze with n balls Algorithm - Optimise finding time-based events Algorithm - Fastest way to check if a number is a vampire number? PHP - How to get innerHTML of DOMNode? PHP - How to create a pagination bar with "..." fillers MySql - How to create a hierarchical recursive query? JavaScript - Promise resolved earlier with p.then(resolve) than with resolve(p) JavaScript - Are ES6 template literals safer than eval? JavaScript - filter() for Objects JavaScript - Sort version-dotted number strings JavaScript - Calculate arithmetic expression w/o eval JavaScript - How to version control objects
Updated on June 14, 2021Comments
-
trincot almost 3 years
This is the error I get when I run my web application in an instance of the Tomcat servlet container started by NetBeans. To fix this I even changed the heap size in netbeans.conf, but still it shows the same error. How can I keep this from happening?
HTTP Status 500 - -------------------------------------------------------------------------------- type Exception report message description The server encountered an internal error () that prevented it from fulfilling this request. exception javax.servlet.ServletException: Servlet execution threw an exception org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:362) root cause java.lang.OutOfMemoryError: Java heap space note The full stack trace of the root cause is available in the Apache Tomcat/5.5.9 logs.
-
brady about 15 years
-
Steen about 13 years
-
vkraemer almost 13 yearsthe righter answer to this question is actually stackoverflow.com/questions/717550/…. The heavily upvoted answer is a good answer for a different question.
-
-
VonC about 15 yearsTrue. +1. Although, would I have been the one writing this answer, I would have included the picture javapassion.com/handsonlabs/nbprofilermemory/index_files/… , from javapassion.com/handsonlabs/nbprofilermemory ;) (but that's just me: I always include picture)
-
VonC about 15 years"I always include picture": as you have noticed lately: stackoverflow.com/questions/707194#707206 (in the comments)
-
palantus about 15 yearsHow do you find appropriate pictures, though? I tried to find a screenshot and couldn't.
-
palantus about 15 years+1 - Sometimes I get so caught up in answering a question that I don't address the real problem.
-
Dana the Sane about 15 years+1 OP should also definitely review that class for excessive object creation, etc.
-
duffymo about 15 years@mmyers - +1 for you, because it happens to all of us. 8)
-
Admin about 15 yearsThe problem is that,there is no VM options in the run category of the project properties.So,im struck up there again!!
-
palantus about 15 years@divya: Could you give us a screenshot or something? I have all the web application plugins uninstalled right now, so I can't easily reproduce your problem.
-
James Schek about 15 yearsI don't think this applies to Servlet Projects... only desktop projects.
-
vkraemer almost 13 yearsThis answer describes how to reconfigure the Java process that NetBeans creates to run the Tomcat servlet container, which is the JVM that is running out of memory.