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

java.lang.OutOfMemoryError: PermGen space

Sam Venkata
Ranch Hand

Joined: Mar 06, 2006
Posts: 68
Hi guys,
I have this memory exception( java.lang.OutOfMemoryError: PermGen space).
I know I need to increase the memory size by altering the JAVA_OPT's
-XX ermSize=128m -XX:MaxPermSize=196m parameters from the command line, but I use Tomcat 6.0 as a windows service, I want the changes to occur automatically instead of using the command prompt. Can somebody help me with this.
Thanks,
Samanth.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

This forum is for J2ME, Mobile Device Apis.

I am going to move this to the Tomcat forum for the tomcat scripts is where you will want to add this stuff to.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61095
    
  66

Please do not cross-post the same question in multiple forums. It wastes people's time when multiple redundant conversations take place.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

If you chose the to include the "start menu items" when you installed Tomcat, go to:
Start -> Programs -> Apache Tomcat -> Configure Tomcat and click on the Java tab.
From there, you can add your JVM settings in the appropriate field.



Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Sam Venkata
Ranch Hand

Joined: Mar 06, 2006
Posts: 68
Ben,
I changed the javaoptions parameter in service.bat and the parameter
-XX:MaxPermSize=128m is appended to the list of java options in the tomcat6w.exe.
Now I have another question.. it is how do I make sure that 128m is being used by the tomcat as the max perm size. Is there a way I could do it. please let me know.

Thanks,
Samanth.
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
Check method of class java.lang.Runtime.


Rahul Bhattacharjee
LinkedIn - Blog
Sam Venkata
Ranch Hand

Joined: Mar 06, 2006
Posts: 68
Rahul,
I did see the Runtime class but it does not have any method that determines the perm space size. All I want to know is if the perm size is set to the new mwmory size...

Thanks,
Samanth.
Sam Venkata
Ranch Hand

Joined: Mar 06, 2006
Posts: 68
Rahul,
I did see the Runtime class but it does not have any method that determines the perm space size. All I want to know is if the perm size is set to the new mwmory size...

Thanks,
Samanth.
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
Sorry that I have diverted from the post.I do not think that you can find the prem size from the memory information that is available from Runtime Class.

This link might be useful.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by Samanth Marisetty:
Ben,
I changed the javaoptions parameter in service.bat and the parameter
-XX:MaxPermSize=128m is appended to the list of java options in the tomcat6w.exe.
Now I have another question.. it is how do I make sure that 128m is being used by the tomcat as the max perm size. Is there a way I could do it. please let me know.

Thanks,
Samanth.



Here.
Paste this into a JSP in the ROOT webapp of Tomcat and hit it.
Sam Venkata
Ranch Hand

Joined: Mar 06, 2006
Posts: 68
Ben,

Thanks a million.. that worked.

Samanth.
Sam Venkata
Ranch Hand

Joined: Mar 06, 2006
Posts: 68
Ben,
Is there a way I could reclaim the committed memory which could be onr of the the problems we have on our server during high loads..

Thanks,
Samanth.
Sam Venkata
Ranch Hand

Joined: Mar 06, 2006
Posts: 68
what i meant was can I reclamin the used memory.. by the pattern that I noticed the used memory is never released until I restart the computer...
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

First, it's normal for your memory consumption to continually rise with Java.
This doesn't necessarily mean that there is a problem. Java's garbage collector, intentionally runs only when it needs to because garbage collection (gc) is very expensive. So, a steady rise in heap space usage is normal.

If you have a memory leak (which in Java means unintentional object reference retention) then, when you get to the point where your app is about to run out of heap space gc will be run but won't be able to reclaim the memory held by those objects.

A common example for web applications is the failure to return database connections to the connection pool. If an app uses a connection pool but doesn't return the connections to the pool then, the pool manager will have to start creating a new connection for every request made to the app. Since the pool itself holds a reference to the connection, it can never be garbage collected. Since the pool never knows that a connection that was used is now available to go back into the pool, it just sits there and consumes memory.
Eventually, either the database will stop allowing more connections or the JVM will run out of heap space.

When this happens, allocating more heap space to the JVM will only postpone the problem.


After raising the amount of memory, are you still getting out of memory exceptions? If so, is it heap memory or perm gen space?
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by Samanth Marisetty:
Is there a way I could reclaim the committed memory which could be onr of the the problems we have on our server during high loads..


You can suggest that the JVM run garbage collection with the:
System.gc() command.
It may or may not happen and Sun recommends that you never put this command into your applications. It is much better to let the JVM manage gc than to try to micro-manage it yourself.

Of course, if you have a memory leak (as described above), running gc will get you nowhere because gc can't reclaim memory if it's being used by an active Java object.
Sam Venkata
Ranch Hand

Joined: Mar 06, 2006
Posts: 68
Ben,
This is what is happening..

localhost
MEMORY TYPE: Code Cache
Used: 4 mb
Committed: 4 mb
Max: 48 mb
------------------------------------
MEMORY TYPE: PS Eden Space
Used: 25 mb
Committed: 33 mb
Max: 54 mb
------------------------------------
MEMORY TYPE: PS Survivor Space
Used: 0 mb
Committed: 1 mb
Max: 1 mb
------------------------------------
MEMORY TYPE: PS Old Gen
Used: 10 mb
Committed: 227 mb
Max: 455 mb
------------------------------------
MEMORY TYPE: PS Perm Gen
Used: 14 mb
Committed: 16 mb
Max: 128 mb
------------------------------------



localhost
MEMORY TYPE: Code Cache
Used: 4 mb
Committed: 4 mb
Max: 48 mb
------------------------------------
MEMORY TYPE: PS Eden Space
Used: 26 mb
Committed: 33 mb
Max: 54 mb
------------------------------------
MEMORY TYPE: PS Survivor Space
Used: 0 mb
Committed: 1 mb
Max: 1 mb
------------------------------------
MEMORY TYPE: PS Old Gen
Used: 10 mb
Committed: 227 mb
Max: 455 mb
------------------------------------
MEMORY TYPE: PS Perm Gen
Used: 14 mb
Committed: 16 mb
Max: 128 mb
------------------------------------



localhost
MEMORY TYPE: Code Cache
Used: 4 mb
Committed: 4 mb
Max: 48 mb
------------------------------------
MEMORY TYPE: PS Eden Space
Used: 27 mb
Committed: 33 mb
Max: 54 mb
------------------------------------
MEMORY TYPE: PS Survivor Space
Used: 0 mb
Committed: 1 mb
Max: 1 mb
------------------------------------
MEMORY TYPE: PS Old Gen
Used: 10 mb
Committed: 227 mb
Max: 455 mb
------------------------------------
MEMORY TYPE: PS Perm Gen
Used: 14 mb
Committed: 16 mb
Max: 128 mb
------------------------------------


the Eden Space is increasing each time a request comes.... all I was trying to know is that if it could be made 0 if there are no requests for some time.

Thanks,
Samanth.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Eden space is heap memory.
I will never go to zero while the app is running.
Tomcat and your app will, naturally, always hold on to some of it.

Again, unless you have a memory leak in your app, a steady rise in consumption is normal and nothing to be alarmed about.


Make a JSP called gc.jsp with this in it:


Put it on your system,
Hit your app till the heap space rises a bit.
Hit gc.jsp
Then look at the JSP the other JSP you just made.
You should see a drop in heap space usage.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Again, JVMs treat System.gc as a suggestion and may, according to the conditions within the JVM ignore it so don't be alarmed if what I suggested in the last post doens't cause a drop in memory consumption.

This might interest you:
http://java.sun.com/docs/hotspot/gc5.0/gc_tuning_5.html
[ March 30, 2007: Message edited by: Ben Souther ]
Sam Venkata
Ranch Hand

Joined: Mar 06, 2006
Posts: 68
Ben,
Thanks a lot for the information, now I understand that eden space is designed to grow but what I could not understand is whether permgen behaves the same way as edenspace. I was looking at the jconsole memory monitoring and managing tool and found that isUsageThresholdSupported for the edenspace is true, but what I understand from
http://java.sun.com/javase/6/docs/technotes/guides/management/mxbeans.html
is that it should be false. Can you please let me know if what I understand is correct.
And also I would like to know if the permgen space could keep growing because it is the area where the classes, methods and such are stored and if so is there a way I could free it .
I really appreciate your help.

Thanks,
Samanth.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java.lang.OutOfMemoryError: PermGen space