[java] Needing bigger Java heap space

Started by
7 comments, last by arachidyl 18 years, 4 months ago
Hello there! The situation is that we need to publish our game on next week but we got some heap problems :) We have done our code ready for adding better sounds and so for latest version but then we got this error: java.lang.OutOfMemoryError: Java heap space After I Googled I found some help to make heap size bigger than normally. So we used this value in Ant xml file and we are using Eclipse IDE if that has something to do with this error: <jvmarg value="-Xmx512m "/> After trying to run our game with better sounds and graphs we got this error: [java] Invalid maximum heap size: -Xmx512m [java] Could not create the Java virtual machine. Well even how hard I have tried to do research I havent found out whats going on here. We have tried all kind of -Xmx values and even with -Xmn values but still we are getting same errors. Thanks!
Advertisement
The option -Xmx512m is correct and should set the maximum java heap size to 512 megabytes. Did you try to run the application from the shell instead of calling it from Eclipse IDE ? May the additional space inside the XML tag be a problem ?

Which kind of operating system and JRE are you using ? How much RAM do you have ?

Did you try to switch to another garbage collector ?
Maybe this may be of interest:
http://java.sun.com/docs/hotspot/gc5.0/gc_tuning_5.html

Well got it working when I added this line in jnlp-file <j2se version="1.4+" initial-heap-size="16m" max-heap-size="256m"/> Still im wondering why wont this work when we are using "ant prompt-run" command in command prompt.

  <!-- =================================================================== -->    <!-- Run Targets                                                         -->    <!-- =================================================================== -->    <target name="prompt-run" description="">        <java            classname="game.GameManager"            classpath="game.jar;jl1.0.jar;mp3spi1.9.3.jar;tritonus_share.jar;"            fork="true"            dir="${basedir}"            failonerror="true"            >        	        	<jvmarg value="-Xms16M -Xmx256M "/>    </java>  </target>


I have 1 gb ram and jre1.5.0_05 that im using. Yes im trying to use it from shell and this space isnt the problem. Hasnt watched your link but I will do it after house cleaning :)

One more interesting thing is that when im runing our game from shell by using this line <jvmarg value="-Xprof "/> it will give me stat in shell. After im ysing this line <jvmarg value="-verbosegc "/> I cant get any stat in shell. Perhaps this has something to do with heap problem too...
How about this Ant target:
  <!-- =================================================================== -->    <!-- Run Targets                                                         -->    <!-- =================================================================== -->    <target name="prompt-run" description="">        <java            classname="game.GameManager"            classpath="game.jar;jl1.0.jar;mp3spi1.9.3.jar;tritonus_share.jar;"            fork="true"            dir="${basedir}"            failonerror="true"            maxmemory="512m"            >        	    </java>  </target>


Here the inner tag 'jvmarg' is replaced by maxmemory.


Also did you try to run the game without the help of Ant by directly calling the jvm ?

Do you have multiple JVMs installed on your system ? Then maybe Ant uses the wrong one.
Thanks bro this really works!

Well I never tested to run this game without ant-file. Im pretty sure that it will work without ant-file. I already tested one smaller version of this game with those heap informations and it worked fine. Perhaps our problem is that I really have another JVM installed in my computer.
I think that you have to use the "line" attribute with command line arguments, and not the "value" attribute as you were doing.

that would make the jvmargs line look like this:

<jvmarg line="-Xms16M -Xmx256M " /><!-- instead of: --><jvmarg value="-Xms16M -Xmx256M " />



If I remember correctly, but it makes sense because the compiler arg element is the same, and for orthogonality, I suspect it would be the same for the jvmargs. So, either way will probably work.

L-
"Education is when you read the fine print; experience is what you get when you don't." -Pete Seegerwww.lucid-edge.net
This even helped me more! Right now everything is going so well here, thanks to u all.

Release parties are coming on thursday and after that need to start plan another projects ;) Nothing so big or revolutionary isnt going to released. Im just so proud to release my first game. Well not mine, more like ours :)
Unless you are loading that many images and sounds, it looks like you might have a memory leak. Such things are entirely possible in java - just google for "memory leak java" and you will get info on how memory leaks happen and how to use a heap analyzer tool to check for problems. The garbage collector is great but it doesn't get everything.

If not I hope that memory usage is on max quality...a lot of people still only have 512MB ram, if you're aiming to low-budget some people could even have only 256MB.
Well we do not need 512mb memory. More like 256 or not even that. Just need to get some stat about memory use.

Well I have one more question about this memory thing. If im running game from dos prompt by using this information in xml-file:

<jvmarg line="-Xms164M -Xmn15M -Xmx256M -verbose:gc -XX:+PrintGCDetails"/>

I will get 85fps in game. But after im running game from jnlp-file with this informations:

<j2se version="1.4+" initial-heap-size="15m" max-heap-size="164m"/>

I will get only 43fps. So whats the problem with this jnlp-file running? Basically im asking how to add same memory configurations in jnlp-file that we are using in xml-file.

This topic is closed to new replies.

Advertisement