miksutrikku, on 03 September 2011 - 04:42 PM, said:
I think this is happening to all people on this topic and more. Would someone tell me how to
Java tends to overallocate memory, by around 480MB and as you traverse further in MC this grows further. Many sites are incorrectly telling users that they need to allocate more when in fact the problem is that too much is allocated; especially on the 32bit java.
Minecraft allocates Xmx1024M and Xms512M itself, which translates to 1490MB Virtual Allocated, and around 690 Private allocation (This is the Commit / Paged size).
The problem is the Virtual allocated. Java RE x86 is not large address aware, which means when the default settings get close to 1980MB, the VM will crash out and you end up with either blocks turning invisible or the Out of Memory error.
On 32bit windows, this is even lower, you can usually only get to around 1.75GB of virtual allocated before the app crashes.
Once you get into a world, Virtual allocation increases to 1800MB.
Java x64 will take on the allocation limit of the OS, which is 64GB(theoretically it could be much less given we are only using 48bit for the memory addressing on current cpu's).
Minecraft on this version of JRE will allocate and use as much ram as is available, up to the point where you start eating into the non paged Kernel Memory area.
The real fix is to preallocate as little as possible, so that Java only allocates new blocks as required by memory growth. the XMx and XMs settings are not limits, they are preallocation blocks. What also helps is enabling Java Garbage collection.
I use the following batch to set my gamedata location and optimise the allocation blocks
@echo off
Title Minecraft Launcher
set APPDATA=%CD%\
"c:\Program Files\Java\jre7\bin\javaw.exe" -XX:+UseConcMarkSweepGC -XX:+CMSIncrementalMode -XX:ParallelGCThreads=5 -XX:+CMSIncrementalPacing -XX:+UseAdaptiveGCBoundary -XX:SurvivorRatio=16 -Xmn1M -Xmx2M -Xms2M -jar minecraft.exe
you can also use
@echo off
Title Minecraft Launcher
set APPDATA=%CD%\
start javaw.exe -XX:+UseConcMarkSweepGC -XX:+CMSIncrementalMode -XX:ParallelGCThreads=5 -XX:+CMSIncrementalPacing -XX:+UseAdaptiveGCBoundary -XX:SurvivorRatio=16 -Xmn1M -Xmx2M -Xms2M -jar minecraft.exe
with this, Jave goes from this (I'm not listing Working set, since its roughly 95% of the commit most of the time).
Start - 630MB Private(Commit), 1478MB Virtual
Menu - 820MB Private(Commit), 1724MB Virtual
In Game - 1,102MB Private(Commit), 2095MB Virtual (Hangs near instantly)
to
Start - 48MB Private(Commit), 1325MB Virtual
Menu - 298MB Private(Commit), 1623MB Virtual
In Game - 704MB Private(Commit), 1979MB Virtual (Hangs near instantly)
this will probably still be too much on x86 copies of windows, so the the normal view distance should be used to drop this further.