Eclipse + Tomcat – java.lang.OutOfMemoryError: Java heap space

In Eclipse IDE, run a Java web application with Tomcat server plugin, but the console prompts


Exception in thread "x" 
	java.lang.OutOfMemoryError: Java heap space

1. Solution – Increase Heap Size in Tomcat

By default, Tomcat allocated a small amount of heap size. To solve it, you need to increase the Tomcat’s heap size manually.

1.1 In server view, double clicks on the Tomcat Server icon.

tomcat-eclipse-heap-size-1

1.2 Clicks on the “Open launch configuration” link.

tomcat-eclipse-heap-size-2

1.3 Clicks on the “Arguments” tab, and append the following VM options at the end of the VM arguments :


-Xms<size> - Set initial Java heap size
-Xmx<size> - Set maximum Java heap size

In this example, we increase the heap size to -Xms512m -Xmx1024m, it should be enough for most of the projects.

tomcat-eclipse-heap-size-3

2. Know Your Heap Size

To know how much heap size is allocated in Tomcat, append this VM option -XX:+PrintFlagsFinal (refer figure 1.3). Start Tomcat, you will noticed the entire VM values are dump to the console, find following names :

  1. InitialHeapSize
  2. MaxHeapSize
tomcat-eclipse-heap-size-4

P.S The value is in bytes.

References

  1. Java heap memory size

About the Author

author image
mkyong
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities.

Comments

avatar
6 Comment threads
0 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
6 Comment authors
maria joseAbub SakirChandra SekharAusgur Troliowuxincheng Recent comment authors
newest oldest most voted
maria jose
Guest
maria jose

Gracias!

Abub Sakir
Guest
Abub Sakir

My kong we are at together good thank

Chandra Sekhar
Guest
Chandra Sekhar

i am not using eclipse,,,, how to increase heap size . pls urjent

Ausgur Trolio
Guest
Ausgur Trolio

Mykong One of the best sites, absolutely love it. Simple and to the point!!

wuxincheng
Guest
wuxincheng

Thanks, done it!

Shaheem Effendi
Guest
Shaheem Effendi

Mykong One of the best sites, absolutely love it. Simple and to the point!!