{"id":2355,"date":"2022-08-30T15:24:10","date_gmt":"2022-08-30T15:24:10","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/01\/05\/permgen-error-in-java-while-memory-usage-seems-low-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:24:10","modified_gmt":"2022-08-30T15:24:10","slug":"permgen-error-in-java-while-memory-usage-seems-low-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/permgen-error-in-java-while-memory-usage-seems-low-collection-of-common-programming-errors\/","title":{"rendered":"PermGen error in Java, while memory usage seems low-Collection of common programming errors"},"content":{"rendered":"<p>Java application dies from time to time with PermGen space error, but when I look at the memory usage it seems low from what I can tell.<\/p>\n<p>It is a Tomcat application, plus there is SOLR server running (under the same tomcat).<\/p>\n<p>JVM params in <code>catalina.sh<\/code>:<\/p>\n<pre><code>-Xms1024m \n-Xmx2048m \n-XX:+HeapDumpOnOutOfMemoryError \n-XX:HeapDumpPath=\/path\/to\/logs\n<\/code><\/pre>\n<p>Error in <code>catalina.out<\/code>:<\/p>\n<pre><code>java.lang.OutOfMemoryError: PermGen space\nDumping heap to \/path\/to\/logs\/java_pid22335.hprof ...\nHeap dump file created [107041478 bytes in 1.823 secs]\nException in thread \"pool-5-thread-1\" java.lang.OutOfMemoryError: PermGen space\n<\/code><\/pre>\n<p>Now the first strange thing is that memory dump is only 100Mb, while heap limit is 2048Mb. When I used to have &#8220;proper&#8221; out of memory errors, dump file was close in size to the heap limit.<\/p>\n<p>Second strange thing is memory usage shown by <code>jmap -heap 22335<\/code> seems pretty normal (when this command was run the java app was still down):<\/p>\n<pre><code>Attaching to process ID 22335, please wait...   \nDebugger attached successfully.\nServer compiler detected.\nJVM version is 11.3-b02\n\nusing thread-local object allocation.\nParallel GC with 16 thread(s)\n\nHeap Configuration:\n   MinHeapFreeRatio = 40\n   MaxHeapFreeRatio = 70\n   MaxHeapSize      = 2147483648 (2048.0MB)\n   NewSize          = 2686976 (2.5625MB)\n   MaxNewSize       = -65536 (-0.0625MB)\n   OldSize          = 5439488 (5.1875MB)\n   NewRatio         = 2\n   SurvivorRatio    = 8\n   PermSize         = 21757952 (20.75MB)\n   MaxPermSize      = 88080384 (84.0MB)\n\nHeap Usage:\nPS Young Generation\nEden Space:\n   capacity = 566689792 (540.4375MB)\n   used     = 13467648 (12.84375MB)\n   free     = 553222144 (527.59375MB)\n   2.3765467792297907% used\nFrom Space:\n   capacity = 327680 (0.3125MB)\n   used     = 0 (0.0MB)\n   free     = 327680 (0.3125MB)\n   0.0% used\nTo Space:\n   capacity = 327680 (0.3125MB)\n   used     = 0 (0.0MB)\n   free     = 327680 (0.3125MB)\n   0.0% used\nPS Old Generation\n   capacity = 1431699456 (1365.375MB)\n   used     = 86216248 (82.22222137451172MB)\n   free     = 1345483208 (1283.1527786254883MB)\n   6.021951579200712% used\nPS Perm Generation\n   capacity = 88080384 (84.0MB)\n   used     = 88080080 (83.99971008300781MB)\n   free     = 304 (2.899169921875E-4MB)\n   99.99965486072358% used\n<\/code><\/pre>\n<p>I looked at the memory dump file, nothing unusual there. Tried increasing heap limit, no difference.<\/p>\n<p>Any ideas what could it be and why the dump file is so small, so is the memory usage while the app continues throwing out of memory errors?<\/p>\n<ol>\n<li>\n<pre><code>PS Perm Generation\n   capacity = 88080384 (84.0MB)\n   used     = 88080080 (83.99971008300781MB)\n   free     = 304 (2.899169921875E-4MB)\n   99.99965486072358% used\n<\/code><\/pre>\n<p>There&#8217;s your culprit. PermGen is used for class definitions, and you seem to have a lot of them!<\/p>\n<p>Try cranking up your PermGen size by adding this to your Tomcat launch options:<\/p>\n<pre><code>-XX:MaxPermSize=256M\n<\/code><\/pre>\n<p>&#8230;but if your application is smashing into your current limit, this change will only give you some extra time between crashes.<\/p>\n<p>Monitor how it behaves and how quickly the usage grows, but be ready to do some digging in your application code for problem class definitions.<\/p>\n<\/li>\n<li>\n<p>Max PermGen size is set by a separate command line switch, try <code>-XX:MaxPermSize=128M<\/code>, that should be enough for PermGen.<\/p>\n<\/li>\n<\/ol>\n<p id=\"rop\"><small>Originally posted 2014-01-05 22:16:58. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>Java application dies from time to time with PermGen space error, but when I look at the memory usage it seems low from what I can tell. It is a Tomcat application, plus there is SOLR server running (under the same tomcat). JVM params in catalina.sh: -Xms1024m -Xmx2048m -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=\/path\/to\/logs Error in catalina.out: java.lang.OutOfMemoryError: PermGen [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2355","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2355","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=2355"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2355\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=2355"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=2355"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=2355"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}