Java Heap Space Error - Very Urgent
Hi all,
I am doing a Desktop application.... I am using swings..... While using my application i get the following error.I have no idea about this error.
Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space
Please help me in solving this problem.Its very urgent
Thanks in advance
Ravi
It does not matter how 'urgent' this is, without more to go on this is just about an impossible request.
you need to increase the heap size. google "increase java heap size"
Hi sabre,I apologise....Bur could you please help me to solve this problem. i am working with eclipse.How to set the heap size of the jvm. Thanks in advanceRavi
How to set the heap size of the jvm
As suggested, Google it.
Note that it's not a realistic option for applets.
Anyway, heap size may not be the problem. Maybe you've just written something that leaks like a sieve or tries to load something enormous into memory.
Have a think about your code. Is there anything that's likely to be occupying lots of heap space? Lots of images? Big images? Other media files? Highly compressed files? Huge database tables?
> Hi sabre,
> I apologise....Bur could you please
> help me to solve this problem. i am working with
> eclipse.How to set the heap size of the jvm.
>
> Thanks in advance
> Ravi
There are a million things that may cause this problem. It may be that you can solve the problem by increasing the heap size but how can anyone tell. Chances are it one of the following
1) You are trying to load a very large file into memory.
2) You are trying to load millions of database records into memory.
3) You have an infinite recursion.
4) You are just short of memory.
I don't use Eclispse (I use Netbeans) but when I get an 'out of memory' exception it normally means I have a design problem OR I have a coding error. I rarely need to increase the heap size.
Hi guys,
Your suggestions are correct. I am importing images, and media files into my application.Thats why its running out of memory. But i cant avoid importing these things. Is increasing the heap size is the only way to do that?
if so, i tried to increase the heap size like java -Xmx1024m -jar myjarfile.jar.
Now its not showing any error.
Is this the right way to do?
Please give your suggestions.
Thanks in advance
Ravi
Upping the heap space will of course give you more memory to play with, but there are a few reasons why you might not want that to be your full solution:
1. it's no good for applets
2. if you up it to something which approaches the machine's available Ram and/or there are a number of other applications running, you'll find that it results in paging memory to disk - your application will still work but it will be dog slow and horrible to use
3. if you need to start loading more or larger images/media files then you're just fighting fires
You can employ some tactics to economise on memory usage. You should take a look at your application and ask yourself these questions:
1. do you really need all these things in memory at once?
2. are you storing files in memory in their compressed (ie file format) form as well as their uncompressed (eg Java Image) form
3. can you resample any images smaller and throw away the larger ones?
4. can you simply use smaller media files?
If you aren't using all the files all the time, you may well benefit from using a cache based on SoftReferences (see here for a bit about reference objects - http://java.sun.com/developer/technicalArticles/ALT/RefObj/) -properly implemented, this will allow you to keep some temporarily unused objects kicking about unless the GC "needs" the space. Sadly, Sun's VM interprets that "need" rather oddly and seems very eager to clear soft references when there's no need to do so, so I ended up having to put in a cute little trick to stop them getting unnecessarily wiped. But you can't have that :o)
> 1) You are trying to load a very large file into memory.> 2) You are trying to load millions of database records into memory.> 3) You have an infinite recursion.> 4) You are just short of memory.Or there's a memory leak.