[Support] Run out of Memory A lot? {1.12}

Discussion in 'Player Guides, Tips and Tricks' started by finch_rocks_1, Oct 11, 2014.

  1. Hey EMC,

    I am here as i seen Many Players say they run out of memory and dont know how to fix it. So i made a Tutorial for that here on EMC.

    Why should I allocate more memory?:
    Normaly Minecraft works fine with his 1GB RAM. But if you allocatte more memory, you can better some situations:
    • More RAM for texture pack buffering (128x ++)
    • More RAM for singleplayer and multiplayer maps buffering (less reloading)
    • Better working with RAM intensive mods
    • Faster map rebuild
    First notice:
    This tutorial requires that you've installed a full Java version, (Java SE) or Java Developement Kit (JDK, includes SE) on your system. Else it might not work right. Installing the right Java version (also important: 32/64 bit) often solves many problems.
    "Minecraft runs out of memory" happens often while running it with the wrong Java version! The preinstalled Java on new Computers-Systems might not support this.
    If you don't have installed Java, get it here!

    What do I have to do:

    NEW launcher:
    Since Minecraft version 1.9.X you can use the new launcher. With this, it is possible to integrate Java commands directly into the game. Here is what you have to do:
    1. Download and execute the new launcher
    2. In the section "Launcher Options" and click on (Your Version/profile you will use {For example Forge/Lite 1.12})
    3. Under "{Your Profile Name}, activate "JVM Arguments" {Will have to move switch from Gray to Green to edit} and add into the text area this argument:

      -Xmx4G -XX:+UseG1GC
    4. Save this profile and execute Minecraft. You will always start with 2GB of RAM
    Need more ram? You can adapt the number to your needings (see RAM Versions)




    And Here for the Final, you can see under Mem, i have 4GB, with only 37% of that allocated.

    Which numbers can I insert?:

    You can adapt the numbers to your needings:
    • -Xmx is the maximum of RAM wich Minecraft can allocate.
    Java 32bitonly supports up to 4GB. The limit depends on the system, if you got an error, try less allocation.
    Be sure to use the right and newest Java version (64bit on 64bit-systems is recommended).

    1GB total allocated
    -Xmx1G -XX:+UseG1GC
    2GB
    -Xmx2G -XX:+UseG1GC
    3GB
    -Xmx3G -XX:+UseG1GC
    4GB
    -Xmx4G -XX:+UseG1GC
    5GB
    -Xmx5G -XX:+UseG1GC
    6GB
    -Xmx6G -XX:+UseG1GC
    8GB
    -Xmx8G -XX:+UseG1GC
    and so on ...

    Notice: You can't give Minecraft more Ram than you have! Else you will recieve an Error!

    How much space can I allocate?:

    At least not more than you've installed in your system.
    To see how much RAM is free, open the Task Manager and change to the Performance Tab. Look how much Physical Memory is available / free.

    Note that other programs and your system also need RAM to work:
    Some numbers for example:
    • Windows Vista Home Basic: 512 MB RAM
    • Windows Vista Home Premium, Business, Enterprise, Ultimate: 1GB RAM
    • Windows 7: 1 GB RAM (32-Bit) or 2 GB RAM (64-Bit)
    • Windows 8 / 8.1: 1 GB RAM (32-Bit) or 2 GB RAM (64-Bit)
    • Linux: 1-2 GB
    • Skype: 256 MB
    • Teamspeak: 64 MB
    • Firefox: 512MB
    Forge and LiteLoader does not allow it?:
    When i tested this on my installation, i found that when you install say forge, it will reset the settings and then reset again when you add LiteLoader. So when you are looking to install these, you will have to reset these settings again.



    As you can see i have 4GB set for my Mem, with 69% allocated while having forge and liteLoader installed.

    Something doesn't work? Possible solutions:
    First of all check your batch file on spelling mistakes. This is one of the most frequently faults.
    Then be sure you've installed a full Java version! Pre-installed versions might not support more memory.

    Error "Could not create Java virtual machine":

    • Remove -Xms[RAM] and try again
    • Adjust the numbers, try both at the same level
    • Check if you've enough free RAM. Do you use 64bit (when greater than 4GB)?
    Did i forget to Post something or need any more help, Feel free to post here and i will be happy to help you.

    Thanks

    ~Finchy
  2. Small Update Noted by Aikar!

    Well I don't know about those kind of things. If you have a specific need like that then go for it, but ultimately the way java works, when you have a large heap (which is what these memory settings control), it makes the system "pause" longer to scan the entire thing looking for memory to free.

    Pauses are what causes noticable lag just as much as slow code. I've done extensive work on EMC fine tuning the garbage collection process and actually lowered max memory before.

    Ultimately here is our final settings:

    Code:
    // I've added notes on why they make sense to use.
    // Many found on this thread: http://www.spigotmc.org/threads/server-launch-sh.35/ by other
    // Large and experienced server owners.
    // Also see official Oracle JVM Tuning section: www.oracle.com/technetwork/java/tuning-139912.html#section4.2.6
    $baseOptions = ''
            . ' -Dfile.encoding=UTF-8' // Ensure files save as UTF8. Things break without this. See: EMC-261
            // == GC Tuning ==
            // This is low pause, keep server from ever spiking.
            // Very good details on why this is beneficial for MC: http://www.oracle.com/technetwork/java/gc-tuning-5-138395.html#0.0.0.%20The%20Concurrent%20Low%20Pause%20Collector|outline
            .' -XX:+UseConcMarkSweepGC -XX:+UseParNewGC'
            // Enable I-CMS, optimizing pauses and distrbutes GC over longer period so TPS keeps stable
            .' -XX:+CMSIncrementalMode -XX:+CMSIncrementalPacing'
            //Uses more CPU but we have unused cores. So this is beneficial to keep TPS affect low.
            .' -XX:+CMSParallelRemarkEnabled' // Use multiple threads for CMS Sweeps
            //. ' -XX:+UseG1GC' // G1GC try it out
            . ' -XX:MaxGCPauseMillis=20' // Ensure never more than 1 TPS lost
            . ' -XX:+DisableExplicitGC' // Prevent plugins causing GC
            // == Misc Tweaks==
            . ' -XX:+AggressiveOpts' // Enables soon-to-be-default optimizations.
            . ' -XX:+UseFastAccessorMethods' // Optimizes getters... pretty respectable deal.
            . ' -XX:+UseBiasedLocking' // Enables a technique for improving the performance of uncontended synchronization.
            // Bukkit synchronizes things for safety that is never contended under ideal cases. This
            // Optimizes those cases, so that uncontended syncs are much cheaper.
            // == Memory Management ==
            . ' -XX:TargetSurvivorRatio=90  ' // Use the survivor area more effeciently.
            //. ' -verbose:gc '
            . ' -Xloggc:gc.log -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCTimeStamps -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=128K ' // Log the GC to file
            .' -XX:LargePageSizeInBytes=2M  -XX:+UseLargePages ' // The biggest gain, but we need to configure system to use it
    ;
    $gameOptions = $baseOptions . ' -Xmx9G -Xms5G'; // Give servers plenty of memory
    $bungeeOptions = $baseOptions . ' -Denvironment=production -Xms2G -Xmx4g -DIReallyKnowWhatIAmDoingISwear=1';
    
    I noticed OP has mojangs -XX+UseConcMarkSweepGC removed. It's EXTREMELY important to keep that or use G1GC at least.
    So your games arguments should be like
    Code:
    -Xmx4G -XX:+UseG1GC
    at the shortest.
    G1GC and ConcMarkSweep are something you choose one of (dont use both!!) and in my testing they are extremely close in benefits, but we settled on the older fashioned CMS for now.
    Mojang has defaulted CMS in the games profile, so if you removed it, you should add it back.
    DO NOT leave it up to Java to use default. Default is bad for MC.
    ShelLuser, Tahitan and Luckygreenbird like this.
  3. Thanks,
    Luckygreenbird likes this.
  4. I defenitely should try this later today, or tomorrow. Thank you for this post. :)
    the_creeper_lord likes this.
  5. If you have any problems let me know, i will try my best to help.
    I have setup mine to have 8 GB, and my map loads way faster on the server now, aswell as when i am in the wild.
    Luckygreenbird likes this.
  6. How many GB of RAM do you have in your pc if you're willing to offer up 8GB? :p
  7. i have 16 GB in my laptop :p
    Luckygreenbird likes this.
  8. :O
    I only have 8GB in my desktop xD
  9. Woo, thank you for the interesting and very helpful guide Finch!! :)
  10. A much better Java argument would be -xmx4096m -xms1024m, this means Minecraft starts with 1GB of RAM and if it requires more it will allocate it in real time up to 4096m (4GB)

    There is no performance benefit from increasing the amount of memory Minecraft can use, the only reason for assigning more memory is to fix crashing. Loading benefits are a placebo.

    P.S Minecraft servers are hungry for RAM, I had a FTB server use 25GB once, so make sure you keep an eye on the amount of memory they use :)
    sambish20 likes this.
  11. Thanks for that small info post, Moved it up to the top, :)
    Luckygreenbird likes this.
  12. Bump for some of the new players,
    Luckygreenbird likes this.
  13. Didn't work for me, got something like
    ''Error: Could not create the Java Virtual Machine.
    Error: A fatal exception has occurred. Program will exit."
    Why is that? I used -Xmx2048m -Xms1024m, and I have 8GB in my system. Can you help me? Thanks.
  14. Have you installed a 64 bit java?

    Also have you tried just ( -Xmx2048m -Xms2048m ) First if not try that and get back to me, :)
    Luckygreenbird likes this.
  15. -just replying so you don't feel ignored :p- I think I have 64 bit java, and I think I have tried that too
    I'll come back to you tomorrow :p
  16. You don't need to convert to megs, -Xmx8G works fine too

    But its important to note giving MC that much memory actually hurts performance. You should only set a max of 2-3GB~

    I would stress 1.5-2 for anything below 1.8, but 1.8 uses so much memory now 2-3 is likely needed.
    ShelLuser and Gawadrolt like this.