15

There is a lot of lag when I play Minecraft. I think this is due to the low amount of RAM I've allocated to Minecraft. (495MB)

How do you allocate more RAM to Minecraft?

I checked my other computer (Intel i5 Core) and it had the same amount of RAM allocated to Minecraft. However, Minecraft did not lag on that computer.

After I installed Optifine on this computer, the lag stopped (I don't know why cause I read that Optifine splits the load onto 2 cores, but I have only one core (At least I think so, a sticker on the laptop says Intel CORE i7)).

5
  • 1
    Here is a good optimization guide. Note that simply allocating more RAM may not always actually help. MineCraft can perform worse with too much RAM allocated - for example, it is recommended not to use more than 512MB for vanilla. The amount needed depends on the mods and texture packs you are using.
    – mellamokb
    Commented Jun 13, 2013 at 16:06
  • 1
    Core i7 can have between 2-6 cores, depending on the model, so Optifine should help allot. Also, this may not apply to you but I had a laptop which was really laggy for Minecraft and I realised I didn't have the best graphics drivers installed. I was using the default chipset, and not the Nvidia drivers. After installing the Nvidia drivers it worked amazingly. Make sure you have the drivers for the correct graphics card (Should be a sticker on your laptop next to the i7)
    – Brandyn
    Commented Jun 14, 2013 at 11:15
  • @ReallyGoodPie Well that's strange, cause I checked device manager, and I have 8 cores.
    – MerajA
    Commented Jun 15, 2013 at 6:01
  • I was just going off of wikipedia, which states that it has up to 6 cores. I thought i7 could have 8 cores, but assumed I had it wrong.
    – Brandyn
    Commented Jun 15, 2013 at 6:05
  • 1
    @ReallyGoodPie An Intel Core i7 has between 2-6 physical cores, which appear to the operating system as 4-12 logical cores through hyper-threading.
    – Philipp
    Commented Nov 11, 2013 at 13:08

8 Answers 8

18

Before you allocate RAM there are some things you should know:

  • x64 systems can allocate up to 192GB when using Windows Professional or above. 16GB when using Windows Home Premium and 8GB when using Home Premium and Starter. Also, please be aware of the physical limits imposed by your CPU Architecture.
  • x32 systems can allocate up to 1GB (This is from personal experience on a 8GB machine and a 3GB machine, please correct me if I'm wrong)

So it is recommended you have a x64 system to allocate as much RAM as possible. Try an leave at least 1GB for the general system processes and stuff like that.

Here is how you allocate RAM on a windows system:

  1. Create a new document and save it as run.bat
  2. Type the following this is for 4GB:
C:\<location to your javaw>\javaw.exe -Xmx4096M -Xms2048M -jar <location of your Minecraft exe>

So basically, the xmx is your maximum RAM your allocating and your xms is the minimum ram it should use.

Here is an example of an actual run.bat:

"C:\Program Files\java\bin\javaw.exe" -Xmx4096 -Xms2048 -jar "C:\users\user\Desktop\minecraft.exe"

Or if you have assigned Java in your system variables

javaw -Xmx4096 -Xms2048 -jar "C:\users\user\Desktop\minecraft.exe"

Obviously don't just copy my code, as you need to find out where A) Your javaw.exe is located and B) where your minecraft.exe

Remember: 1GB = 1024MB and 0.5GB = 512MB

Old Launcher Introduced in 1.6

With the new launcher, it is allot easier to allocate RAM to your Minecraft. Simply go ahead and edit a profile and where it says "Java Settings (Advanced)", tick all the check boxes. Then add the amount of RAM you would like to the JVM Arguments text box. For example if I wanted to run it with 1GB I would simply type -Xmx1G and the 1G will indicate 1GB of RAM. xmx indicates the maximum RAM to allocate.

Profile Editor

Ensure that you have the correct path to your java and that you have JDK installed.

Latest Launcher

In the latest launcher, if you go to the "installations" tab, go to the edit installation settings for that particular version, scroll down and select more options, you're able to change the max amount of RAM by simply changing the -Xmx parameter.

New Launcher Example

ALTERNATIVELY

Simply download the tekkit pack and there is an option to play vanilla Minecraft. Simply select the "Cog" or settings icon in the top right corner and it will give you an option to allocate RAM if other methods are failing. Good Luck

Also if you are having trouble doing any of this, just simply google it and there are literally 100s of posts similar to this and allot of tutorials.

12
  • Gives me invalid or corrupt jarfile minecraft.jar error
    – MerajA
    Commented Jun 13, 2013 at 17:02
  • Have you tried the technic pack way? and are you using Windows, mac or a Linux Distro? Also, are you referencing a minecraft.exe or a minecraft.jar? Try to use a minecraft.exe for the purpose of this.
    – Brandyn
    Commented Jun 13, 2013 at 22:02
  • Um, that's the error I get while opening my file. I'll try the technic way......
    – MerajA
    Commented Jun 14, 2013 at 6:46
  • I asked the questions so I could know why this is happening ^_^. Technic way should work no matter what though, if you have enough RAM
    – Brandyn
    Commented Jun 14, 2013 at 11:11
  • @Meraj99 You may also want to check the amount of background processes and applications you have running on that computer. Try and close everything except Minecraft
    – Brandyn
    Commented Jun 15, 2013 at 1:53
4

It is explained in full by this video (and the following text was found here with edits as found in the comments).

In essence this video denotes 3 main steps:

  1. Moving Minecraft to a folder. (Make sure this is the actual minecraft.exe and not a shortcut)

  2. Creating a text file using note pad, and write out (this example is for 2GB of RAM):

java -Xmx2048M -Xms1048M -jar “minecraft.exe” Note: If you are experiencing issues with this when running Windows 8 try deleting the quotation marks around Minecraft.exe. Alternatively, try and switch java to javaw instead. Credit to “Anon” in the comments!

  1. Save this file as a .bat and store it in the same file which you store Minecraft.exe.

Note: this example uses 2GB of RAM, for more or less RAM add intervals of 1024 for each additional GB.

5
  • I get a error, Unable to access jarfile %minecraft.bat
    – MerajA
    Commented Jun 13, 2013 at 6:36
  • 2
    Xms is the minimum memory to allocate to the program and Xmx is the maximum it is allowed to grow to. As such, these numbers being the same is not necessary and sometimes not a good idea. Try setting a range (e.g. -Xms1024m to -Xmx2048m). Commented Jun 13, 2013 at 6:40
  • Now I have "Invalid or corrupt jarfile minecraft.jar"
    – MerajA
    Commented Jun 13, 2013 at 6:43
  • 2
    @Meraj99 did you remove the meta-inf (for mods)? then you need to add the main class net.minecraft.Minecraft Commented Jun 13, 2013 at 7:30
  • What's the net.minecraft.Minecraft thing....
    – MerajA
    Commented Jun 13, 2013 at 17:03
3

This is how my .bat file looks like in the MC folder:

start /high javaw -Xms2048m -Xmx4096m -jar minecraft.exe

If this gives you an error as well then you might want to download the java SDK, it gives more functionality.

Running the bat as administrator might help too.

5
  • Gives me invalid or corrupt jarfile minecraft.jar error
    – MerajA
    Commented Jun 13, 2013 at 17:05
  • Did you install java SDK? If so try completely erase java from your PC and do a clean install.
    – Madmenyo
    Commented Jun 13, 2013 at 17:14
  • Eh, nope... still doesn't work.
    – MerajA
    Commented Jun 13, 2013 at 17:40
  • Did you clear it completely and installed it from scratch? There was no trace in the registry not even when you reboot? Java can be very annoying to remove it leaves traces everywhere. Try searching for files. If i have some more time i try to find a good source online. This Issue MUST be your java. What do you get if yu just type "java" in the CMD?
    – Madmenyo
    Commented Jun 13, 2013 at 21:36
  • I get lots of things starting with "Usage:"
    – MerajA
    Commented Jun 14, 2013 at 6:47
2
  1. Go to control panel
  2. Search Java
  3. Click on Java
  4. Click on Java at the top
  5. Click view
  6. You will see something like this: -Xmx2048m
  7. Click on that then backspace until it looks like this: -Xmx
  8. Now add your desired amount of RAM in Mb, then an m it should look something like -Xmx4096m (when you set it to 4GB)
1

Here's an example of direct optimization through .bat file

start javaw -Xms4096K -Xss128M -Xmx2048M -XX:PermSize=24m -XX:MaxPermSize=32m -XX:+UseParallelOldGC -XX:ParallelGCThreads=4 -XX:+CMSIncrementalPacing -XX:+AggressiveOpts -XX:+UseThreadPriorities -XX:+UseFastAccessorMethods -XX:+UseBiasedLocking -XX:+UseStringCache -XX:+TieredCompilation -XX:SurvivorRatio=8 -Dsun.java2d.noddraw=true -Dsun.java2d.d3d=false -Dsun.java2d.opengl=true -jar Spoutcraft-Launcher.jar

This one is for spoutcraft but you can just replace it on minecraft launcher's exe name and be done with it. If something goes wrong you can probably remove biased locking and string cache, along with tiered compilation and also setup parallelGCThreads to be equal your amount of cores.

1

Do you need to allocate more RAM? Often the default heap size is fine for your machine. Minecraft is unusual because it tends to be CPU-bound rather than GPU- and memory-bound. But it is possible your Java heap is too small.

To determine whether your Java heap is big enough:

  1. Open Minecraft and launch any world.
  2. Show the debug screen (press F3).
  3. In the top right corner, look for a line that says "Mem: X% Y/Z MB." X and Y will be constantly increasing. Z will generally not change much, but see the next line.
  4. The line below that will say "Allocated: W% Z MB"; if this remains less than 100% after you play for a while, that means Java is not using its maximum heap size. This is rather unusual, but it may mean you are not under serious memory pressure (i.e. you don't need a bigger heap), or it may simply mean that Java is not good at figuring out how big its heap should be. This cannot happen if you're using the -Xms and -Xmx options described in other answers, since they force the minimum and maximum heap sizes to be the same.
  5. Play for a while, until the "Mem" line has reached 100% and gone down a few times. This is called "garbage collection," and indicates that the Java runtime is reclaiming memory which the application (Minecraft) is no longer using. Pay attention to how often this happens.
  6. If it's happening very frequently (e.g. once a second) or you see the percentage constantly oscillating near 100%, you probably don't have enough memory on Java's heap. If it does not happen very often, but you see lag when it does, your collection runs are too slow. Adding more memory may help with this to a point, since it allows for better generational garbage collection (only collecting some of the dead memory some of the time). However, there are diminishing returns here, and you may need a better CPU if you continue to observe this behavior after adjusting the heap. In this case, you might also experiment with -XgcPrio:pausetime, but YMMV on whether that accomplishes anything whatsoever.

As a rule of thumb, do not make the heap bigger than your actual physical RAM. You will just cause the application to begin swapping or paging.

0

Create a .bat file. This is how mine looks:

javaw -Xmx4096 -Xms2048 -jar "C:\Users\nope\Desktop\minecraft.exe"

(The reason why the nope is in there is that my computer's account name is "nope".)

The -Xmx4096 and -Xms2048 are what allocate more memory to Java (and therefore to Minecraft). Mine set the maximum to 4096MB (4GB) and the starting allocation to 2048MB (2GB), and you can allocate more or less by changing those numbers in the command.

2
  • Can you try and elaborate a bit? This is very unclear and doesn't really help as it currently is.
    – shanodin
    Commented Aug 11, 2013 at 3:21
  • This just repeats what ReallyGoodPie's answer already says more clearly and in more detail. Commented Aug 11, 2013 at 6:44
-1

It's worth noting at this point that as of version 1.6 and on the launcher has changed and there is now a new (arguably easier) way to allocate more memory to Minecraft.

You can do this by:

  1. Opening up the Minecraft launcher.
  2. Clicking the "Edit Profile..." button at the bottom left.
  3. Ticking the JVM Arguments box at the bottom of the menu.
  4. Changing the value of -Xmx1G, where 1G already equals 1GB of RAM.
2
  • 2
    Please don't keep linking to outside sources. This smells like spam. If there's more information available, add it to your answer. That way, if that site ever goes down, your answer can still stand on it's own.
    – Frank
    Commented Nov 14, 2013 at 21:46
  • 3
    Hey TastySausage, having done some investigating I'm pretty sure that both minecraftman.com and the out-of-memory website are yours. It's actually OK to link to your own sites here but you must disclose your connection to the link for it to be OK. Doing otherwise, your posts will probably be deleted and you risk deletion of your account. You may have useful answers to contribute. If you wish to continue using Arqade, you should link to your site in your profile and disclose your conflict of interest in answers that use your site. Otherwise, we can assume you're just here for SEO. Commented Nov 14, 2013 at 22:33

Not the answer you're looking for? Browse other questions tagged or ask your own question.