51

I have written a code and I run it a lot but suddenly I got an OutOfMemoryError:

  Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
        at javax.media.j3d.BoundingBox.<init>(BoundingBox.java:86)
        at javax.media.j3d.NodeRetained.<init>(NodeRetained.java:198)
        at javax.media.j3d.LeafRetained.<init>(LeafRetained.java:40)
        at javax.media.j3d.LightRetained.<init>(LightRetained.java:44)
        at javax.media.j3d.DirectionalLightRetained.<init>(DirectionalLightRetained.java:50)
        at javax.media.j3d.DirectionalLight.createRetained(DirectionalLight.java:116)
        at javax.media.j3d.SceneGraphObject.<init>(SceneGraphObject.java:119)
        at javax.media.j3d.Node.<init>(Node.java:178)
        at javax.media.j3d.Leaf.<init>(Leaf.java:50)
        at javax.media.j3d.Light.<init>(Light.java:270)
        at javax.media.j3d.DirectionalLight.<init>(DirectionalLight.java:87)
4
  • 1
    A note for something that may pop up later, if you get errors about being out of perm space, the flag for that is -XX:PermSize=<someNumber>m and -XX:MaxPermSize=<someNumber>m Commented Mar 4, 2010 at 18:50
  • Look at the following: Exception in thread “main” java.lang.OutOfMemoryError: Java heap space. This site has some information that might turn useful. Commented Nov 7, 2011 at 17:42
  • Possible duplicate of java.lang.OutOfMemoryError: Java heap space Commented Nov 17, 2015 at 10:46
  • You should increase PHY RAM memory in your machine. After i upgraded the VM or PHY maschine memory, the java issue gone. I used before java11 -Xmx2048m -jar JARFILE - but there was not enough memory freed for buffer. Commented Mar 17, 2022 at 12:01

6 Answers 6

69

Well, it's fairly self-explanatory: you've run out of memory.

You may want to try starting it with more memory, using the -Xmx flag, e.g.

java -Xmx2048m [whatever you'd have written before]

This will use up to 2 gigs of memory.

See the non-standard options list for more details.

Sign up to request clarification or add additional context in comments.

6 Comments

Just add bunch of heap? Don't we want to investigate whether there is a memory leak??
@Zwei: Not to start with. Just changing it to use more memory is an extremely simple way to try to improve the situation to start with. If it works, great - and if it doesn't, you've lost almost nothing in trying.
@Jon: Perhaps if you do a duration test anyway it's okay.. I was worried that it will mask the leak for a prolonged time and make it difficult to find the leak for the developer. But hell, you probably know million times better than me so ;)
@Zwei: It depends who the end user is. If Johanna is going to give the program to someone else to run, then it does make sense to find out why it ran out of memory. If she's only going to use it herself, then it doesn't matter - if it's fine for another couple of months and then she has a problem, she can fix it then.
|
7

If you're recompiling a disassembled APK with APK tool:

Just Set Memory Allocation a little bigger

set switch -Xmx1024mto -Xmx2048m

java -Xmx2048m -jar signapk.jar -w testkey.x509.pem testkey.pk8 "%APKOUT%" "%SIGNED%"

you're good to go.. :)

2 Comments

Where exactly does he mention anything about an APK?
may be not, but I look for the error on google, and google directed me to this link. any one with this problem will be shown this page, as I am recompiling Android APK
3

You're out of memory. Try adding -Xmx256m to your java command line. The 256m is the amount of memory to give to the JVM (256 megabytes). It usually defaults to 64m.

Comments

3

I don't know about javax.media.j3d, so I might be mistaken, but you usually want to investigate whether there is a memory leak. Well, as others note, if it was 64MB and you are doing something with 3d, maybe it's obviously too small...

But if I were you, I'll set up a profiler or visualvm, and let your application run for extended time (days, weeks...). Then look at the heap allocation history, and make sure it's not a memory leak.

If you use a profiler, like JProfiler or the one that comes with NetBeans IDE etc., you can see what object is being accumulating, and then track down what's going on.. Well, almost always something is incorrectly not removed from a collection...

Comments

3

enter image description here -Xmx1024m -XX:MaxPermSize=512m -Xms512m

Add this parameter as argument in your server params

Comments

0

There is a another best/effective way to solve this error,

for example, let's take a loop which counts till 10 thousand, here you may get the error Out of memory, do to solve it you can give the computer time to recover.

So, you can sleep for 400-500ms before you're loop counts the next number :

new Thread(new Runnable() {
            public void run() {
                try {
                    sleep(550); // 550 ms (milli seconds)
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }).start();

By doing this, will make you're program slower but you don't get any error till the heap space is full again, so by waiting some ms, you can prevent that error.

You can apply this method other than loop.

Hope it helped you, :D

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.