Fix Apache Tomca: java.lang.OutOfMemoryError: PermGen spaceError


java.lang.OutOfMemoryError: PermGen space

There are many reasons that you may get an OutOfMemoryError when you are running your application in Apache Tomcat server.

  1. Too many classes loaded in PermGen area.
  2. Memory leaks in your application.
  3. Trying to parse a huge file in memory.
  4. Using DOM XML parser to parse a huge XML file.
  5. Huge resultset received from Database.
PermGen = Permanent Generation

You get this error when the PermGen memory area is full. The PermGen area is the part of the Java heap that is used to store information related to metadata like class declarations, methods and object arrays.

How to fix PermGen Error

Its also recommended to use profiling tools such as jconsole to see which classes are taking up space. If you think its due to the size allocated from PermGen using the JVM argument, then change them as follows in the Tomcat configuration file,

  1. Open Tomcat -> bin directory.
  2. Create a file named "setenv.bat" if on Windows or setenv.sh for macOS/Linux/Unix,
  3. Add the below lines in the file.

    Windows
    set "JAVA_OPTS=%JAVA_OPTS% -Xms512m -Xmx1024m -XX:MaxPermSize=512m -server"

    macOS/Linux/Unix
    export "JAVA_OPTS=%JAVA_OPTS% -Xms512m -Xmx1024m -XX:MaxPermSize=512m -server"
  4. Restart tomcat.
Advertisements
Try Out Code2care Dev Tools:

Advertisements



Android Java Linux Microsoft Google Python macOS Notepad++ Microsoft Teams CSS PHP SharePoint Html Linux C Programs Bootstrap jQuery Sublime Android Studio Facebook Eclipse WhatsApp News MySQL Json HowTos JavaScript FTP S3


Advertisements


Code2care is an initiative to publish and share varied knowledge in programming and technical areas gathered during day-to-day learnings and development activities.

Students and Software Developers can leverage this portal to find solutions to their various queries without re-inventing the wheel by referring to our easy to understand posts. Technical posts might include Learnings, Tutorials, Trouble-Shooting steps, Video Tutorials, Code Snippets, How Tos, Blogs, Articles, etc.
🎉 We are celebrating the 10th years of Code2care! Thank you for all your support! We hope we made a difference.
We strong support Gender Equality & Diversity.

We stand in solidarity with Ukraine - Make a donation to UNHCR - https://donate.unhcr.org/in/en-in/ukraine-emergency