Exception in thread "main" java.lang.OutOfMemoryError: Java heap space

164,638

Solution 1

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.

Solution 2

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.. :)

Solution 3

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

Add this parameter as argument in your server params

Solution 4

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...

Solution 5

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.

Share:
164,638

Related videos on Youtube

Johanna
Author by

Johanna

Updated on October 30, 2020

Comments

  • Johanna
    Johanna over 3 years

    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)
    
    • Carl
      Carl over 14 years
      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
    • DarthVader
      DarthVader over 12 years
      Look at the following: Exception in thread “main” java.lang.OutOfMemoryError: Java heap space. This site has some information that might turn useful.
    • Viktor Mellgren
      Viktor Mellgren over 8 years
    • Tiborcz Kiss
      Tiborcz Kiss over 2 years
      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.
  • OscarRyz
    OscarRyz over 14 years
  • Enno Shioji
    Enno Shioji over 14 years
    Just add bunch of heap? Don't we want to investigate whether there is a memory leak??
  • Jon Skeet
    Jon Skeet over 14 years
    @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.
  • Enno Shioji
    Enno Shioji over 14 years
    @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 ;)
  • Jon Skeet
    Jon Skeet over 14 years
    @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.
  • Johanna
    Johanna over 14 years
    "java -Xms<initial heap size> -Xmx<maximum heap size>" also I have found this.how can I use this?? thanks
  • Daniël van den Berg
    Daniël van den Berg over 8 years
    Where exactly does he mention anything about an APK?
  • Kaleem Ullah
    Kaleem Ullah over 8 years
    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