Is your Minecraft server suffering from sudden tick freezes, rubberbanding, or crashing with java.lang.OutOfMemoryError? In this guide, we break down exactly how much RAM your server actually needs, how to configure startup arguments on Windows and Linux, how to optimize JVM garbage collection flags, and how to adjust memory in modern hosting panels.
Quick answer
- Open your startup script (
start.baton Windows orstart.shon Linux) or hosting panel Startup settings. - Set matching heap flags:
-Xms4G -Xmx4Gso Java allocates the full memory pool upfront without resize stutter. - Add Aikar's tuned G1GC garbage collection flags to prevent Stop-the-World freeze spikes during chunk loading.
How Much RAM Does Your Minecraft Server Actually Need?#
Before modifying any configuration files, it is crucial to understand that more RAM is not always better. Minecraft runs inside the Java Virtual Machine (JVM). When you allocate RAM to Java, you are setting aside memory for the heap—where player positions, loaded chunks, entity states, and block data are temporarily stored.
If you allocate too little RAM, your server crashes with out-of-memory errors. But if you allocate too much RAM (for example, giving 16 GB of memory to a small 4-player SMP), Java's garbage collector will delay cleaning up unused data until the heap fills up, causing brutal 3-second server freeze spikes known as Stop-the-World pauses.
| Server Type | Player Count | Recommended RAM | Optimal Server Jar |
|---|---|---|---|
| Vanilla / Survival | 1 – 5 players | 2 GB – 3 GB | PaperMC / Purpur |
| Semi-Vanilla / SMP (15–30 plugins) | 5 – 15 players | 4 GB | PaperMC / Purpur |
| Light Modpack (20–50 mods) | 2 – 8 players | 4 GB – 5 GB | Fabric |
| Heavy Modpack (150–300+ mods) | 4 – 10 players | 6 GB – 8 GB | Forge / NeoForge |
| Massive Network / Minigames | 25+ players | 8 GB – 12 GB | Purpur / Velocity |
Understanding -Xmx, -Xms, and JVM Heap Behavior#
When launching Minecraft through the command line or terminal, memory allocation is defined by two fundamental Java flags:
-Xms: The initial starting memory allocated to the JVM heap at server boot.-Xmx: The maximum memory limit the JVM heap is permitted to consume under peak load.
The Golden Rule: Always set -Xms and -Xmx to the exact same value (for example, -Xms4096M -Xmx4096M or -Xms4G -Xmx4G). If you set starting RAM lower than max RAM (such as -Xms1G -Xmx4G), the JVM will repeatedly halt game execution to expand its allocated memory pool as players explore new terrain, causing noticeable in-game stutter.
Method 1: Allocate RAM on a Local Windows PC Server#
If you run a Minecraft server on your personal computer, you control RAM allocation through your batch startup file (usually named start.bat or run.bat):
- Open your server folder where
server.jaris located. - Right-click on
start.batand select Edit (or open with Notepad). - Locate the line starting with
java. A standard default line looks like this:java -Xmx1024M -Xms1024M -jar server.jar nogui - Replace the memory parameters with your desired value. For a 4 GB server, change the line to:
java -Xms4096M -Xmx4096M -jar server.jar nogui pause
- Save the file in Notepad, close it, and double-click
start.batto boot your server with the upgraded RAM.
Method 2: Allocate RAM on Linux (Ubuntu / Debian / VPS)#
On Linux dedicated servers and Virtual Private Servers, server launches are managed via shell scripts (start.sh) or systemd service units. Use the following command structure:
Ensure the launch script has execution permissions by running chmod +x start.sh before executing with ./start.sh or wrapping inside a screen or tmux session.
Method 3: Allocate RAM on Control Panels (Pterodactyl & FreeGameHost)#
If you host your server with a game server provider like FreeGameHost or another Pterodactyl-based host, you do not need to edit batch files manually. Memory limits are handled at the container level:
- Log into your game server panel at
panel.freegamehost.xyz. - Select your Minecraft server instance from the server list.
- Navigate to the Startup tab on the left navigation bar.
- Check the Server Memory or Startup Parameters section. Most modern hosts automatically pass the maximum allocated RAM to the Docker container based on your selected plan.
- On FreeGameHost, every free Minecraft server is permanently provisioned with 4,096 MB (4 GB) of dedicated DDR5/DDR4 RAM. Simply start or restart the server, and the container automatically utilizes the full 4 GB memory ceiling.
Best JVM Flags: Aikar's Garbage Collection Flags#
Simply increasing the -Xmx value is only half the battle. Vanilla Java's default garbage collection settings are designed for long-running enterprise web servers, not real-time multiplayer game physics. Minecraft developer Aikar formulated a set of tuned JVM flags specifically designed to smooth out garbage collection pauses in Minecraft:
Why these flags matter:
-XX:+AlwaysPreTouch: Forces the operating system to allocate and zero all memory pages during startup, preventing memory allocation delays while players are actively exploring.-XX:MaxGCPauseMillis=200: Instructs the G1 garbage collector to keep collection pauses under 200 milliseconds to avoid missed game ticks.-XX:+ParallelRefProcEnabled: Uses multiple CPU cores to process Java references during GC cleanup cycles.
How to Identify Memory Leaks and Heap Issues#
If your server is consuming 100% of its allocated RAM within 30 minutes of starting, adding more RAM will only delay the inevitable crash. You likely have a memory leak caused by a poorly coded plugin or corrupted chunk. Follow these steps to diagnose the leak:
- Install the Spark profiler plugin (available for Paper, Purpur, Fabric, and Forge).
- Run the command
/spark heapto see an immediate breakdown of JVM memory allocation (heap used, heap total, non-heap metaspace). - Run
/spark heapdumpto generate a snapshot of all objects living in server memory. You can inspect this file using Eclipse Memory Analyzer (MAT) to identify the exact plugin hoarding data structures. - Audit entity counts by running
/minecraft:kill @e[type=item]or checking mob farms. A mob farm holding 800 cows in a 3x3 pen will exhaust both CPU ticks and memory cache.
Minecraft Heap vs Off-Heap: Why Server Uses More RAM Than Set#
A common point of confusion for server administrators is seeing their server panel or Linux terminal report 4.5 GB or 4.8 GB of memory usage when they explicitly configured -Xmx4G. This is not a memory leak; it is the natural consequence of JVM off-heap overhead.
The -Xmx parameter only restricts the Java Heap. In addition to the heap, the Java process requires native system RAM for several critical components:
- Metaspace (128 MB – 512 MB): Where Java stores loaded class definitions, method bytecode, and plugin metadata. Servers running 50+ plugins will consume substantially more Metaspace.
- Thread Stacks (64 MB – 256 MB): Every concurrent thread in Minecraft (network I/O threads, world generation worker threads, chunk compression threads) allocates a private stack (usually 1 MB per thread via
-Xss). - Native ByteBuffers & Off-Heap I/O: High-performance server forks like Paper and Purpur use native network buffers (Netty) that bypass the Java garbage collector to process player packets faster.
- Garbage Collection Overhead: The G1GC collector itself requires native memory tables to keep track of memory region references.
As a best practice, always ensure your hosting container or physical machine has at least 1 GB of buffer memory above your -Xmx allocation. For example, if you allocate 4 GB to Minecraft, the host environment should provide at least 4.5 GB to 5 GB of total memory to prevent the operating system OOM killer from executing.
Why Free Hosts Limit RAM and Force Long Queues#
Free hosting services like Aternos and Minehut enforce strict RAM caps (often restricted to 1 GB or 2 GB total memory) because they run thousands of user instances on crowded shared servers. To conserve compute resources, they place free users in 20-minute waiting queues and shut down servers after 5 minutes of player inactivity.
At FreeGameHost, we solved this limitation by building an automated container cloud on enterprise NVMe hardware. Every free server receives a dedicated 4 GB of RAM and high-performance CPU cores with zero queue times, zero credit card requirements, and permanent file persistence.
Frequently asked questions#
How much RAM does a Minecraft server need in 2026?
For vanilla survival with 2 to 5 players, 2 GB is sufficient. For Paper or Purpur servers with 10 to 20 plugins and 10 players, 4 GB is the optimal sweet spot. Large modpacks (such as All The Mods 9 or DawnCraft) or heavy network lobbies require 6 GB to 10 GB of RAM.
What is the difference between -Xmx and -Xms?
-Xms defines the initial memory allocation pool with which Java starts the server, while -Xmx specifies the absolute maximum memory ceiling. Setting both flags to the exact same value (e.g. -Xms4G -Xmx4G) prevents Java from dynamically resizing the heap, which eliminates sudden garbage collection freeze spikes.
Can you allocate too much RAM to a Minecraft server?
Yes. Allocating excessive RAM (such as 16 GB to a small 5-player vanilla server) causes Java's Garbage Collector (G1GC) to accumulate gigabytes of stale entity objects before triggering a cleanup. When the cleanup finally triggers, it results in massive 'Stop-the-World' lag spikes lasting several seconds.
What causes java.lang.OutOfMemoryError: Java heap space?
This error occurs when the server's active memory usage exceeds the -Xmx limit. Common causes include running out of RAM during rapid Elytra chunk generation, an uncontrolled entity farm with thousands of mobs, or a memory leak from an outdated plugin.
What does Linux Exit Code 137 mean on a Minecraft server?
Exit code 137 indicates the Linux kernel Out-Of-Memory (OOM) killer terminated the Java process with SIGKILL (128 + 9). This happens when Java heap plus native off-heap memory (Metaspace, thread stacks, JVM overhead) exceeds the host server's total physical RAM limit or Docker container memory limit.


