Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Java in General and the fly likes java.lang.OutOfMemoryError Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "java.lang.OutOfMemoryError" Watch "java.lang.OutOfMemoryError" New topic
Author

java.lang.OutOfMemoryError

Dean Fredericks
Ranch Hand

Joined: Dec 04, 2004
Posts: 60
This question is so tough, even the most senior engineers here at my company still dont know what is going on. To answer this question you need indepth knowledge of how java allocates its memory.

We are running a large business server written in java, it receives requests via corba interface, does some things, and passese on the request to be porcessed at some other location.

The program has run fine for 6 months or so. Then one day , java.lang.OutOfMemoryError.

This is strange because its running on a HP server with over 4 gigs of memory, and the since of the app in the nt-process list says its was about 90 megs when it crash - so there was plenty memory!

Now, we have looked, I have look many people have looked, there is no memory leak in this app.

WHat is happening? Ive got a feeling its to do with the heap size, but shouldnt java just make a bigger heap if it sees it was need more memory ??

Would appricaite any input from anyone who knows how java works, how it allocotes memory, the role the heap plays, and has experience with the out of memory error!!

thanks guys!
cheers !


PLEASE WATCH THIS VIDEO: <a href="http://www.glumbert.com/media/dolphin" target="_blank" rel="nofollow">http://www.glumbert.com/media/dolphin</a><br /> <br /><-- that video is no joke. Spread the word... this cant go on!!!<br /> <br />SCJP 1.4, SCBCD 1.3, SCWCD 1.4, SCMAD 1.0
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

3 possibilities:
Windows will only allow a process to take 2Gig max. I believe this gets better post-Server 2003
Java 1.4 and before will only allow 1.5Gb anyway, this may limit you further.
It may be the heap size. We had this too. It's another -XX option but I'll have to go look for it.

As you may have guessed, we have some app using large chunks of memory.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

Originally posted by Dean Fredericks:

This is strange because its running on a HP server with over 4 gigs of memory, and the since of the app in the nt-process list says its was about 90 megs when it crash - so there was plenty memory!


Sun's JVMs (and most others) have a maximum Java heap size, set on JVM startup. When that heap is filled and garbage collection can't free any memory, you'll get an OutOfMemoryException. The default maximum Java heap size is 64MB, for a total OS memory usage of something like 90MB. It doesn't matter how much RAM the machine has in total -- the JVM won't allocate any more than its preset maximum heap size.

For Sun's JVMs, the command-line switch to set the maximum heap size looks like "-Xmx1234m", where "1234" is the number of megabytes of RAM to use for the Java heap. If you're not using a standard Sun JVM, then check the documentation for the appropriate switch to use.


[Jess in Action][AskingGoodQuestions]
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

-XX:PermSize is what I was trying to remember, just looking for a good link.
[ April 08, 2005: Message edited by: David O'Meara ]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: java.lang.OutOfMemoryError