Skip to main content

Fix Tomcat PermGen Space (Out of Memory)

Tomcat production server sometime will hit the following java.lang.OutOfMemoryException: PermGen space error.

java.lang.OutOfMemoryException: PermGen space
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124) 

It’s usually happened when the Tomcat start and stop few times. It’s just funny, however you can fine tune it with some minor changes in the Tomcat configuration setting. By default, Tomcat assigned very little memory for the running process, the solution is actually quite simple.
All you need todo are

1) create setenv.sh or setenv.bat (windows)

2) add this line if not already exist (depend on what os you are using)
   Linux:
    export set JAVA_OPTS="-Xms512m -Xmx2g"

   Windows 
    set JAVA_OPTS="-Xms512m -Xmx2g"

3) Done. Restart Tomcat.

Explanation:
This error are occurs when JVM cannot create new object on memory heap because it pass the heap size. that is why it says out of memory. when your program start it create a heap in memory stated in -Xms parameter. the amount reserved are the number after the parameter. an the suffix after the number are unit size of the heap. k for kilobit; m for megabit; g for gigabit. And also please adjust the amount of memory allocation based on you machine.

-Xmx are the maximum size of the heap in memory. as long as the the object in your memory don't pass this limit you are good. but when you pass this limit then the java.lang.OutOfMemoryException are raised.

Memory Leak:
Normally your program wont pass maximum heap size. But through time your application create more object in the memory and some time collected by java Garbage Collector when the created object not being used anymore by the program. For some reason these object sometimes still have some reference in your program that can cause Memory Leak. If the problem not fixed then Garbage Collector cannot collect this object then eventually the heap became full and you program cannot create more object. 

Comments

Popular posts from this blog

The Future Of Computing is Ubuntu Phone

As we are know, in the beginning of January 2013. Canonical announce their new project called Ubuntu Phone. From the beginning Ubuntu was just another Linux distro,  but now Canonical driving Ubuntu far beyond its beginnings as just another Linux distro into an Operating System that works on  television and even being  an android and iPhone competitor, Ubuntu is skating to where they puck is going to be. But, which such a bold move, there are significant obstacles to overcome. The soon to be released Ubuntu Phone is paving the way that all smart phones will eventually go. Back to the late  1943 where  computers were gigantic, filling rooms and requiring constant care and maintenance. Over time, the components required to build the computers become smaller and cheaper, till eventually it was possible to put one on your desk until the laptop computer, a smaller, more portable, but just as powerful machine was made and make it nearly obsolete. And then, com...

Parsing XML dengan java SAX Parser

Melanjutkan dari post saya tentang parsing XML dengan Java, pada entri sebelumnya teknik parsing yang digunakan dengan menggunakan DOM Parser. pada entri kali ini saya akan membahas bagaimana cara untuk mem-parsing XML dengan SAX parser. pada entri kali ini kita tetap menggunakan XML dengan struktur yang sama dengan entri sebelumnya. <?xml version="1.0" encoding="UTF-8"?> <personnel> <employee type="permanent"> <name>Seagull</name> <id>3674</id> <age>34</age> </employee> <employee type="contract"> <name>Robin</name> <id>3675</id> <age>25</age> </employee> <employee type="permanent"> <name>Crow</name> <id>3676</id> <age>28</age> </employee> </personnel> pembacaan xml dengan SAX Parser...

It's been a while...

It's been a while since my last blog entry. Maybe this time I'll try to write something into this blog. Something about computer and programming related or something other than that. And for all my reader (is there any?), I want to tell you my appreciation and my best regards... Thank You..