Take the 2-minute tour ×

Due to a small implementation mistake I discovered how quickly I could reach a Java heap space issue

now the bug is fixed everything is fine but it did get me looking into how to solve this and I foudn multiple solution such as

java -Xms5m -Xmx15m MyApp

the problem is that this changes the java memory on my computer, but I'm working on a Applet that is going to be used in a webrowser.

Therefore, is there a way, at RUNTIME in an APPLET to change the heap size ?

share|improve this question

4 Answers 4

up vote 7 down vote accepted

You can add parameters to the applet tag. But the parameter you are interested on is available only on Java6 u10 or later.


    <PARAM name="java_arguments" value="-Xmx256m">

Here more information http://www.oracle.com/technetwork/java/javase/plugin2-142482.html#JAVA_ARGUMENTS

share|improve this answer
Extra memory can also be defined for applets deployed via. JNLP, but this is the simpler method. Note especially the last two links in the applet Wiki (stackoverflow.com/tags/applet/info). Good call on the link & example. (whispers) hopefully some of the other contributors to this thread will learn a thing or two. ;) –  Andrew Thompson Feb 17 '11 at 8:41

AFAIK, only user can change JRE heap settings. Applet can not change this settings.


It seems that in the latest versions of JDK this is possible. Look at: How can I start an Java applet with more memory?


Memory settings can only be set for JNLP apps, not for Applets.

share|improve this answer

If it's not specified on the command line, you have to get it from the JVM settings. So when you deploy your applet to the web, it will be dependent on what memory settings they have on their computer when they run it. Typically it's set to 60-90Mb by default, so try to keep it under that.

Consider the ramifications if the applet could change those settings... what else it might be able to change. That's just asking for a security exploit eventually, and Java aims for security before functionality :)

share|improve this answer

the JVM may have started long before you Applet. It is too late now to change heap size. Try Java Web Start where you can control that, spawning a new JVM for your Applet/application.

share|improve this answer

Your Answer


