I have an applet which needs more or less memory depending on how many data the client has.
We usually recommend to use Java 1.6 latest version, but we actually support Java 1.5+ so we have a protection in the applet which shows a dialog box with a warning about "not enough memory" and instructions where to go to increase the memory.
However, I was really surprised to see that -Xmx works differently in applets and standalone processes and I cannot actually determine if the applet has enough memory.
Here is how it is done:
- the applet receives the following arguments :
- param name="java_arguments" value="-Xmx153m" (of course this works in Java 1.6 update 10, otherwise it will get 64M in Java 1.5 and Java 1.6 prior update 10)
- param name="required.memory" value="153"
- at runtime, we compare required.memory with Runtime.getRuntime().maxMemory()
- with a limit of 153M in an applet we get 143589376 but in a standalone application we get 155516928
- 153 * 1000 * 1000 = 153000000 (I'm not using 1024 for 1K, just in case ) which is definitely more than 143589376.
If I'm using a factor of 0.9 to avoid any approximations in JVM seems to work well, but is this the right value - 0.9? How do they calculate this limit and why is it different in standalone applications and applets?