Windows – How to limit a Java process to a certain amount of RAM

javamemoryminecraftwindows 7

I am trying to limit Minecraft to a certain amount of memory. To that end, I start it from a batch file with the following line:

javaw -Xms256M -Xmx256M -cp Minecraft.exe net.minecraft.LauncherFrame

but it routinely goes over 800 MB.

I also tried going to the Java applet in the Control Panel. Then to Java tab/View…, then added the following runtime parameter:

-Xmx256m

That didn't help either.

What can I do to limit a java process (or at least Minecraft in particular) to 256 MB of RAM.

Best Answer

-Xmx only constrains the Java heap. The code itself, the JVM, OS DLLs, internal Java data structures and thread stacks all take additional memory. In your case, they apparently take more than 550 MB of RAM. No heap setting would bring the total under 256 MB.

However, note that the code parts may be shared across processes. A DLL that uses 5 MB of RAM in your process will generally use the same 5MB of RAM in another process.

Related Question