Java.lang.OutOfMemoryError: Java heap space with NetBeans


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


description The server encountered an internal error () that prevented it from fulfilling this request.


javax.servlet.ServletException: Servlet execution threw an exception

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.

Best Solution

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:

setting the heap size
(Thanks to VonC for finding this picture.)