

To identify the root cause of the problem required lots of investigation, like which object is taking memory, how much memory it is taking or finding the dreaded memory leak. is a kind of error from JVM because of memory leak or objects are consuming memory but not releasing it. But during un-deployment, if the container somehow keeps a reference of any class loaded by application class loader then that class and all related class will not get garbage collected and quickly fill permGen space if you deploy and un-deploy application many times. In application server used different class loaders are used to load different applications so that deploy and un-deploy of one application without affecting of others application on the same server. Generally, it’s happening in webserver and application servers like Glassfish, Weblogic, WebSphere or tomcat. To increase the size of perm space specify a size for permanent generation in JVM options as below.Įxport JVM_ARGS=”-Xmx1024m -XX:MaxPermSize=256m”Īnother reason for “ : PermGen” is memory leak through Classloaders. Point to Remember: Setting heap size by -Xmx no impact on OutOfMemory in perm space. Most JVM default size of Perm Space is around “64MB” which can reach easily by having too many classes and a huge number of Strings in the application. PermGen means the Permanent Generation of the heap is used to store the String pool and various Metadata required by JVM related classes, method and other java primitives. If you are familiar with different generations of heap and garbage collection process, new, old and permanent generation of heap space. You will get in-depth knowledge of this in the below paragraphs. as it’s having an infinite loop and adding tests continuously on the same variable. In the above example, you see a small program can also create OutOfMemoryError because of just small wrong steps. StringBuffer str=new StringBuffer("FacingIssuesOnIt") Įxception in thread "main" : Java heap spaceĪt (Unknown Source)Īt (Unknown Source)Īt (Unknown Source)Īt (Unknown Source)Īt .main(OutOfMemoryErrorExample.java:10) It will add to the point as long as not throw. In the below example try to create by adding the name “Saurabh Gupta” in an infinite loop. OutOfMemoryError : Java heap space Example

OutOfMemoryError(String s): Constructs an OutOfMemoryError with the specified detail message.OutOfMemoryError() :Constructs an OutOfMemoryError with no detail message.Though both of them occur because JVM ran out of memory they are quite different from each other and their solutions are independent of each other. OutOfMemoryError objects may be constructed by the virtual machine as if suppression were disabled and/or the stack trace was not writable. It throws when the JVM cannot allocate an object because of out of memory, and no more memory could be made available by the garbage collector.
