?
Solved

What causes OutOfMemoryError?

Posted on 1998-10-31
10
Medium Priority
?
192 Views
Last Modified: 2006-11-17

Apparently running out of memory, obviously, given the error message.  :)

But I'd like to know why, as it appears to be inconsistent.  I've written two Java programs (a traffic simulator and a lava lamp animation) and both run fine on the SunSPARC (that's where I originally wrote and tested it) -- I can keep it running for hours without a problem.  But when I brought the source (not the bytecode) back to my PC, compiled, and ran it, it gives that Java.OutOfMemoryError within 30 seconds or so (for both applications).  My machine has more physical RAM and HD space than the SPARC (9GB of disk space [2.3GB free] and 128MB of RAM -- running Win95 OSR2 w/ Symantec Cafe v 1.80).  The SPARC only had 40MB of RAM, and less than 300MB of disk space free.

If I got this error on both the SPARC and my PC, my first guess would be that something is wrong with my code, but since it only seems to happen on my PC, I'm wondering if there is a known bug in the Symantec Cafe JVM or even in Java itself -- but I have not read about this from anyone else, and this would appear to be a rather big issue if it were a problem with Java itself, or even Cafe specifically.  

Any ideas?  Thanks!


AP9
0
Comment
Question by:ap9
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 2

Expert Comment

by:sprinkmeier
ID: 1226750
OM does not necessarily mean you machine is out of menory, only that your virtual machine has used up all th ememory it is going to ask for.

try

java -mx100m MemoryHog

to give it up to 100M bytes of RAM. Does that solve it?

0
 
LVL 8

Expert Comment

by:diakov
ID: 1226751
Yes, the VM is usually restricted to 60M of memory. Try specifying more.
0
 

Author Comment

by:ap9
ID: 1226752
Actually, I went back in and manually added calls to java.lang.System.gc() and it seemed to work for one application, but causes the other to crash when you try to close it.

I'll give your suggestions a try and see if it turns out better.  Thanks!


ap9
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:ap9
ID: 1226753
I've tried increasing max heap size up to 200m, but it still seems to run out of memory in the same amount of time.  I tried increasing the Java and C stack sizes, too, to no effect.


ap9
0
 
LVL 2

Expert Comment

by:sprinkmeier
ID: 1226754
Desperation time....
- run it with "-verbosegc" on both machines, see if it does a lot more GC on one that the other.
- Try printing out Runting.getMemory() at various points (or some call with a name vaguely like that) to try to see when/where the memory is being used.
- Add a finalizer to your biggest objects and get them to print out the fact that they have been GC'ed. Make sure you get them collected on both systems.
- print out the stack trace of the OM exeption
- purchase and wave vigorously one rubber chicken

0
 
LVL 16

Expert Comment

by:imladris
ID: 1226755
I found there was trouble with double buffering, at one time. I have an application that we run under Windows and Linux. One or the other would run out of memory during an animation sequence, if it lasted too long. The solution, as it turned out, was to take the getGraphics call out of the loop. I was doing a getGraphics and dispose inside the loop originally, but it appears that the operating system resources that were consumed and supposedly released, during this process, weren't exactly.

0
 
LVL 5

Expert Comment

by:msmolyak
ID: 1226756
You can try to use a tool like JProbe (klgroup.com) or OptimizeIt (optimizeit.com) profiler which tells you excatly what the memory is used for (what and how many objects are allocated) at any point of program execution.  JProbe even presents a graph similar to that of NT perfomance monitor.
0
 

Author Comment

by:ap9
ID: 1226757

sprinkmeier:  I tried that it actually wasn't calling gc at all (that I could see) before it ran out of memory.  When I put the gc calls in there manually, a ton of messages showed up.  Hmm.

imladris:  Yeah, I found that if I inserted gc() calls in my loop it seemed to do better (but for some reason tends to crash when you exit).  I'm passing a GraphicsContext to several objects (which then draw themselves to that object) in a loop, but I'm not sure how to take it out of the loop (since it is nested very deeply -- it's actually called in a method, and that method is called within a loop that isn't part of the class).  Is the idea to just get the graphics context once, and hold on to it and use it?

msmolyak:  Cool!  Thanks for the info -- I'll look into it.


ap9
0
 
LVL 1

Accepted Solution

by:
malexiev earned 300 total points
ID: 1226758
As I understood, you try to do animation. There's a great problem with that (that's "createImage" method). You can see more information in www.javasoft.com in Java Developer Connection. There're some bug reports (in Bug Parade) where the bug is called
"createImage causes memory leaks" or something like that. You can see a lot of comments there. They complains why it works on Sparc and not on WIN 95/NT.

We have the same problem with image creating and try to workaround.
And I think your problem is the same bug.
0
 

Author Comment

by:ap9
ID: 1226759
Hmm, thanks, I think that's the info I need!
0

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month13 days, 17 hours left to enroll

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question