File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Performance and the fly likes OutOfMemoryError: PermGen space Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Performance
Bookmark "OutOfMemoryError: PermGen space" Watch "OutOfMemoryError: PermGen space" New topic

OutOfMemoryError: PermGen space

Jeppe Mariager

Joined: May 09, 2008
Posts: 3
Hey all,

First off, sorry if this has been answered before, i did some searching, but didnt find much i knew how to do.

I'm a totl newbie in the Java world, but my company has recently purchased a new CMS coded in Java, and since i'm a webdeveloper, i got the task of moving our sites to the new system. When i develop on my laptop, i often run into the OutOfMemoryError: PermGen space error. I figured that it's because my java stuff doesnt get as much memory as it should - But my question is, how do i increase this? I checked my memory usage at the time before and after the problem, and i use around 1.3 gig of 3 gig RAM, so i figure that it should be possible to kick some more resources after the java programs.

Here's my current JAVA_OPS from jboss run.conf:

JAVA_OPTS="-server -Xms128m -Xmx1024m -XX :p ermSize=64m -XX:MaxPermSize=512m -Djava.util.logging.config.file=/usr/local/jboss/server/default/conf/"

I figure that it's something in there that needs tweaking, but i'm not sure what exactly?

Thanks a lot for your time if you can help me, it's really appreciated. I'm really starting to like Java, and if i can just get this error fixed, i'll hopefully be flying in no time
[ May 09, 2008: Message edited by: Jeppe Mariager ]
Jelle Klap

Joined: Mar 10, 2008
Posts: 1951

The java.lang.OutOfMemoryError: PermGen space failure is often ran into during development when frequently deploying/undeploying/re-deploying application builds. Increasing the value of -XX:MaxPermSize for the server VM is your best bet at a timely working-around for the issue, as pinpointing the exact cause is usually very difficult.
[ May 09, 2008: Message edited by: Jelle Klap ]

Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
Akshay Kiran
Ranch Hand

Joined: Aug 18, 2005
Posts: 220

"It's not enough that we do our best; sometimes we have to do<br />what's required."<br /> <br />-- Sir Winston Churchill
Jeppe Mariager

Joined: May 09, 2008
Posts: 3
As i said, i use abour 1.3gig/3gig ram when it dies - So i don't think thats the problem.

Anyways, thanks a lot guys, i'll try tweaking the numbers and getting it to run correctly...
Matt Harrah
Ranch Hand

Joined: Aug 05, 2006
Posts: 54
You may want to look at how you are doing String stuff. If you do a lot of String manipulation (and I mean very large amounts in high volume) you can run into this when the string pool gets too big.

From Sun's site:
Interned java.lang.String objects are also stored in the permanent generation. The java.lang.String class maintains a pool of strings. When the intern method is invoked, the method checks the pool to see if an equal string is already in the pool. If there is, then the intern method returns it; otherwise it adds the string to the pool. In more precise terms, the java.lang.String.intern method is used to obtain the canonical representation of the string; the result is a reference to the same class instance that would be returned if that string appeared as a literal. If an application interns a huge number of strings, the permanent generation might need to be increased from its default setting.

One thing you look at is using StringBuffers or StringBuilders to concatenate series of strings, rather using + or +=, particularly inside loops.
Jim Yingst

Joined: Jan 30, 2000
Posts: 18671
String manipulation shouldn't have anything to do with the perm generation unless you use the intern() method. Which is definitely a possibility here, given the symptoms. But if intern() is not used, other string manipulation shouldn't affect this particular problem.

Jeppe: the overall memory usage isn't relevant here. The problem is that the MaxPermSize is too small for what you're using. Definitely try increasing that. But it's also possible that you've got some sort of memory leak that will expand to eventually overflow whatever size you have. If that's the case, increasing the MaxPermSize may delay the problem, but not prevent it. Still, it's very much worthwhile to try increasing the size as Akshay showed, to see what effect that has.

"I'm not back." - Bill Harding, Twister
rajesh bala
Ranch Hand

Joined: Jan 14, 2003
Posts: 66
Can you try with the following options. This could force the JVM to cleanup the permgen as well.

-XX:+UseConcMarkSweepGC -XX:+CMSPermGenSweepingEnabled -XX:+CMSClassUnloadingEnabled -XX:MaxPermSize=128m

I agree. Here's the link:
subject: OutOfMemoryError: PermGen space
It's not a secret anymore!