This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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.
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 ]
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.
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.
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.