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

Mengapa Karyawan Meninggalkan Perusahaan!

Mengapa karyawan meningggalkan perusahaan (atau paling tidak sering ngedumel)? Berikut ini petikan dari bukunya Haris Priyatna yang berjudul Azim Premji, "Bill Gates" dari India (terbitan Mizania 2007). Azim Premji adalah milyuner dari India yang telah menyulap Wipro, dari sebuah perusahaan minyak goreng menjadi konglomerasi perusahaan dengan salah satunya adalah Wipro Technologies yang merupakan ikon kebangkitan industri teknologi informasi di India. Dia urutan ke-21 orang terkaya di dunia versi Forbes 2007. Azim dikenal sebagai milyuner yang bergaya hidup sederhana. Berikut ini pandangan Premji tentang mengapa karyawan betah dan tidak betah dengan perusahaan. Wipro sendiri memiliki tinkat turn-over (kepindahan) karyawan yang sangat rendah, padahal gajinya tidak lebih tinggi dibandingkan perusahaan sejenis seperti Infosys dan TCS. Mengapa KARYAWAN meninggalkan perusahaan? Banyak perusahaan yang mengalami persoalan tingginya tingkat pergantian karyawan. Betapa or

XML Parsing Dengan Java Bag. I (Menggunakan DOM Parser)

Dulu sewaktu kuliah saya pernah pernah berpikir untuk membuat suatu applikasi yang dapat membaca dan menulis file configurasinya sendiri. lalu saya menggunakan text file sebagai media penyimpan konfigurasi.... seiring perkembangan dan jam terbang bertambah sayapun sempat terpikir untuk mengganti text file yang digunakan menjadi XML (Extensible Markup Language) dimana dokumen ini memiliki keunggulan yang sangat banyak. tidak hanya sebagai media penyimpanan konfigurasi, ternyata XML juga banyak digunakan sebagai media penyimpanan data. seperti contoh berikut ini. <?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&

Metal Gear Solid: Ground Zero

During PAX Prime, Metal Gear Solid: Ground Zeroes director Hideo Kojima presented fans with 11 combined minutes of both cinematics and gameplay footage of the Konami developed title. Ground Zeroes (yes, Zero is pluralized) was announced to be the prologue to Metal Gear Solid 5 . Metal Gear Solid: Ground Zeroes stars the original Snake, who has a helicopter that allows him to zip around the world and take on missions in any country he's needed. View slideshow: Metal Gear Solid: Ground Zeroes screens The English subtitled demo opens with kids in rain-soaked cages are presumably being turned into soldiers by men that are clearly 'bad guys'. After receiving reports of an agent held in Cuba with info that could undermine their child training regime, the operatives of XOF board a helicopter in order to 'silence' her. As their chopper leaves, the camera cuts to view Big Boss making his way onto their base. This is an older, grey-haired Snake