OutOfMemoryError  PermGen



Here I look into what is meant when a Java program runs into a OutOfMemoryError: PermGen Space error. I first explain what the permanent generation heap space is, after which I explain the usual cause of the Permgen Space error and I give some pointers on how to avoid it.

 Introduction

 To understand the error, we have to look into how the jvm memory is structured. There are two memory regions in the JVM: the heap and the stack. Local variables  reside on the stack, everything else on the heap. This Java heap memory is structured again into regions, called generations.  The longer an object lives, the higher the chance it will be promoted to an older generation. Young generations(such as Eden on Sun JVM) 
 are more garbage collected than older generations(survivor and tenured on Sun JVM). However, there is also some separate heap space called permanent generation.  Since it is a separate region, it is not considered part of the Java Heap space. Objects in this space are relatively permanent.  Class definitions are stored here, as are static instances and string pools that have been interned

 From experience, the PermGen space issues tend to happen frequently in dev environments really since Tomcat has to load new classes every time it deploys a WAR  or does a jspc (when you edit a jsp file). Personally, I tend to deploy and redeploy wars a lot when I’m in dev testing so I know I’m bound to run out sooner or later.

OutOfMemoryError: PermGen Space

The OutOfMemoryError: PermGen Space error occurs when the permanent generation heap is full. Although this error can occur in normal circumstances, usually, this error is caused by a memory leak. In short, such a memory leak means that a classloader and its classes cannot be garbage collected after they have been undeployed/discarded.

To give an example on how this can happen, let’s say we have a Shape class, which is part of a jar in a web application that is deployed on some webserver. In the lib folder of the web server, there is some logging framework present, which has a Log class with the method register(Class clazz) with which classes
 can be registered for logging. Let’s say that the Shape class gets registered by this method and the Log class starts keeping a reference to the clazz object. When the Shape class gets undeployed, it is still registered with the Log class. The Log class will still have a reference to it and hence, it will never be garbage
 collected. Moreover, since the Shape Class has a reference to its ClassLoader in turn, the ClassLoader itself will never be garbage collected either, and so will  none of the classes it loaded.

An even more typical example is with the use of proxy objects. Spring and Hibernate often make proxies of certain classes. Such proxy classes are loaded by a classloader as well, and often, the generated class definitions – which are loaded like classes and stored in permanent generation heap space – are never discarded,  which causes the permanent generation heap space to fill up


 Avoiding the error

 This should theoretically be less of an issue in production environments since you (hopefully) don’t change the codebase on a 10 minute basis.  If it still occurs, that just means your codebase (and corresponding library dependencies) are too large for the default memory allocation and you’ll just  need to mess around with stack and heap allocation. I think the standards are stuff like:

1. Increasing the PermGen Memory Size

The first thing one can do is to make the size of the permanent generation heap space bigger. This cannot be done with the usual –Xms(set initial heap size) and –Xmx(set maximum heap size) JVM arguments, since as mentioned, the permanent generation heap space is entirely separate from the regular Java Heap space, 
and these arguments set the space for this regular Java heap space. However, there are similar arguments which can be used(at least with the Sun/OpenJDK jvms) to make the size of the permanent generation heap bigger:

 -XX:MaxPermSize=128m

 default is 64m

2. Enable Sweeping
 Another way to take care of that for good is to allow classes to be unloaded so your PermGen never runs out:

-XX:+CMSClassUnloadingEnabled -XX:+CMSPermGenSweepingEnabled

Stuff like that worked magic for me in the past. One thing though, there’s a significant performance trade off in using those, since permgen sweeps will  make like an extra 2 requests for every request you make or something along those lines. You’ll need to balance your use with the tradeoffs.


2

View comments

Hypertext Transfer Protocol (HTTP) is stateless: a client computer running a web browser must establish a new Transmission Control Protocol (TCP) network connection to the web server with each new HTTP GET or POST request. The web server, therefore, cannot rely on an established TCP network connection for longer than a single HTTP GET or POST operation. Session management is the technique used by the web developer to make the stateless HTTP protocol support session state. For example, once a user has been authenticated to the web server, the user's next HTTP request (GET or POST) should not cause the web server  to ask for the user's account and password again.

If not all alot of web applications want to know who is the visitor on their site.
4

SpringMVC FileUpload with ajax & JQuery

If you want to upload a file in a SpringMVC application with ajax you need to do following things

Server Side

On server side there are many ways but MultipartHttpServletRequest is easiest way to do that. On server side you need some logic to handle the file uploaded.For this we will be using apache commons utilities commons-fileupload and commons-io . Include these two jars in the class path of your project.
3

InnoDB vs MYISAM An Accumulation

Introduction

InnoDB

InnoDB is a storage engine for MySQL. MySQL 5.5 and later use it by default. It is included as standard in most binaries distributed by MySQL AB, the exception being some OEM ersions.

Can static methods be overrriden?

It is not possible to override static methods. If a subclass defines a static method with same signature as a static method which is defined parent class. Method in child class will be hiding the method in parent class. This phenomena is called method hiding. However if you override a static method compiler will not give an error. That means, if you try to override, Java doesn't stop you doing that.

OutOfMemoryError  PermGen

Here I look into what is meant when a Java program runs into a OutOfMemoryError: PermGen Space error. I first explain what the permanent generation heap space is, after which I explain the usual cause of the Permgen Space error and I give some pointers on how to avoid it.

Introduction

To understand the error, we have to look into how the jvm memory is structured. There are two memory regions in the JVM: the heap and the stack.
2

Base 64 Encoding and Decoding

Base64 is a group of similar binary-to-text encoding schemes that represent binary data in an ASCII string format by translating it into a radix-64 representation.

The term Base64 originates from a specific MIME content transfer encoding.

Base64 encoding schemes are commonly used when there is a need to encode binary data that needs to be stored and transferred over media that are designed to deal

with textual data.

i wrote a simple plugin for openfire. It is very simple one.It just catches the traffic of openfire and prints it to info.log. It has been very much helpful in working and debugging with applications for openfire.

i found good material on using maven with scala i am resharing it for further use.

Introduction to maven

Maven is a builder like make or ant, written in java. It's a commande line tool, IDE (Eclipse, Netbeans, IDEA) have plugins to handle and integrate project powered by maven. It could be used to create lib (jar), webapps (ear) and any other type of "artifact". It prefers convention over configuration, and configuration over instruction.
1

The SCP protocol is a network protocol, based on the BSD RCP protocol,[1] which supports file transfers between hosts on a network. SCP uses Secure Shell (SSH) for data transfer and uses the same mechanisms for authentication, thereby ensuring the authenticity and confidentiality of the data in transit. A client can send (upload) files to a server, optionally including their basic attributes (permissions, timestamps). Clients can also request files or directories from a server (download).

Last day i was configuring a ubuntu system as my work machine. First of all i tried to install eclipse an IDE most basic requirement for a developer's machine. in ubuntu 12.04 by default Eclipse Indigo is available but i wanted Eclipse Kepler.i downloaded eclipse from their site extracted it in some folder and tried to run it by double clicking eclipse in its folder nothing happend.
1
Blog Archive
About Me
About Me
Loading