Tomcat – java.lang.OutOfMemoryError: PermGen space

Often time, Tomcat may hits the following java.lang.OutOfMemoryError: PermGen space error.

java.lang.OutOfMemoryError: PermGen space
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(

It’s usually happened after the Tomcat restarts a few times.

1. Solution

By default, Tomcat is assigned a very little PermGen memory for the running process. To fix it, increase the PermGen memory settings by using the following Java VM options.

-XX:PermSize<size> - Set initial PermGen Size.
-XX:MaxPermSize<size> - Set the maximum PermGen Size.

In the next step, we will show you how to set the VM options in Tomcat, under Windows and Linux environment.

2. Windows

Tomcat is managed by this script file catalina.bat, dive inside the script, you will find out that catalina.bat always find and run the setenv.bat file to set the environment variables.

rem Get standard environment variables
if not exist "%CATALINA_BASE%\bin\setenv.bat" goto checkSetenvHome
call "%CATALINA_BASE%\bin\setenv.bat"
goto setenvDone
if exist "%CATALINA_HOME%\bin\setenv.bat" call "%CATALINA_HOME%\bin\setenv.bat"

2.1 To set the environment variable on Windows, create a setenv.bat manually, and put it into the ${tomcat-folder}\bin folder.

set JAVA_OPTS=-Dfile.encoding=UTF-8 -Xms128m -Xmx1024m -XX:PermSize=64m -XX:MaxPermSize=256m

P.S No double quotes, set JAVA_OPTS={value}.

2.2 Restart Tomcat, it will call the setenv.bat file to set the environment variable automatically.

{$tomcat-folder}\bin\catalina.bat restart

3. Linux

On Linux, the process is same, just Tomcat is using and instead.

3.1 Find out where is :
$ sudo find / -name ""
find: /dev/fd/3: Not a directory
find: /dev/fd/4: Not a directory

3.2 Review the, script, it behaves like Windows, but use instead.

# Ensure that any user defined CLASSPATH variables are not used on startup,
# but allow them to be specified in, in rare case when it is needed.
if [ -r "$CATALINA_BASE/bin/" ]; then
  . "$CATALINA_BASE/bin/"
elif [ -r "$CATALINA_HOME/bin/" ]; then
  . "$CATALINA_HOME/bin/"

3.3 Create a manually, and put it into the ${tomcat-folder}\bin\ folder.

export JAVA_OPTS="-Dfile.encoding=UTF-8 -Xms128m -Xmx1024m -XX:PermSize=64m -XX:MaxPermSize=256m"

P.S With double quotes, export JAVA_OPTS=”{value}”.

3.4 Restart Tomcat.

The heap size and non-heap size (perm gen) value is just an example, you should change the value accordingly to suit your project needs.


  1. Configure Tomcat Memory Settings
  2. Oracle : Presenting the Permanent Generation
  3. Useful JVM Flags – Part 5 (Young Generation Garbage Collection)
  4. How To Install Tomcat On Ubuntu
  5. Find Out Your Java Heap Memory Size
Tags :

About the Author

Founder of and, love Java and open source stuff. Follow him on Twitter, or befriend him on Facebook or Google Plus. If you like my tutorials, consider make a donation to these charities.


  • http://[email protected] Ayas

    The above solutions (setting PermSize & MaxPermSize) sometimes don’t help while doing a hot deploy or redeploy of a web application in tomcat. I could see PermGenSpace:OutOfMemory error while doing that in my tomcat.

    Got resolved by adding -XX:+UseConcMarkSweepGC and -XX:+CMSClassUnloadingEnabled parameters to the tomcat startup script along with the other parameters. -XX:+CMSClassUnloadingEnabled parameter clears the PermgenSpace which is a non-heap memory.

  • Awanish yadav

    In catalina.bat file. can i simplay PAST these line or its 1st need to “SET”

    JAVA_OPTS=”-Djava.awt.headless=true -Dfile.encoding=UTF-8
    -server -Xms1536m -Xmx1536m
    -XX:NewSize=256m -XX:MaxNewSize=256m -XX:PermSize=256m
    -XX:MaxPermSize=256m -XX:+DisableExplicitGC”

  • Goycochea

    Plz , how to change the “Xms” and “PermSize” value on Apache Tomcat 7 ?

    • Anita

      -XX:PermSize=###m -XX:MaxPermSize=###m

  • Garima

    Thanks a ton! Worked very well for me! :)

  • WiN

    It worked for me :)

  • Bhaskar

    Thanks a lot.

    I was wondering is there any way to set it through a java config class for a java web application so that we just have to copy paste the war into any tomcat installations.

  • Dilip Shah

    Very helpful… thanks!

  • Victor

    Thanks!!! This is the n-th time you save me ;). Keep up the good work!

    • Almir

      Victor said what I want to say!!!

      Thank you!!!