What the error looks like
Error occurred during initialization of VM
Could not reserve enough space for 4194304KB object heapThe number is the memory Java was asked for, and 4194304 KB is 4 GB. This is not OutOfMemoryError, which hits after the game is already running. Here nothing ran at all. You may also see Invalid maximum heap size: -Xmx..., Invalid initial heap size or Initial heap size set to a larger value than the maximum heap size. Same family.
Fix 1: ask for less
The computer didn't have that much free. Lower the number: in a launcher it's the memory slider or -Xmx in the JVM arguments, and in a start command you change -Xmx8G to -Xmx4G. On Linux, don't judge by the free column of free -h, because the system keeps spare RAM as file cache. Read the available column instead.
Fix 2: use a 64-bit Java
A 32-bit Java can't hold more than about 1.5 GB, so a larger -Xmx fails even on a machine with plenty of RAM. Run java -version. A 64-bit build prints 64-Bit Server VM on the last line. If yours doesn't, install a 64-bit Java and pick it in your launcher. The Java version guide covers which one to get.
Fix 3: check -Xms
-Xms is the starting size and it can't be bigger than -Xmx, the maximum. -Xms8G -Xmx4G fails with Initial heap size set to a larger value than the maximum heap size. The usual setup keeps them equal:
java -Xms4G -Xmx4G -jar server.jar noguiOn a hosting panel the RAM setting is capped by your plan, and setting it above what the plan includes can trigger this error. Lower it, or ask support.
Questions
What's the difference from OutOfMemoryError?
This error stops Java before the game starts, because the memory can't be set aside. OutOfMemoryError happens after it started, when the game used up what it was given.
Why does -Xmx2G work but -Xmx8G doesn't?
Because 8 GB isn't free on that machine, or the Java is 32-bit. Raise the number step by step until it stops starting, or close other programs first.
How much memory should I give it?
Vanilla is fine on a few gigabytes. Modpacks and busy servers often want 4 to 8 GB. Never ask for more than the computer can spare.
Keep reading
- How to fix OutOfMemoryError in MinecraftMinecraft crashed with java.lang.OutOfMemoryError? See what the message means and how to give the game or server more memory in your launcher or start command.
- How to fix UnsupportedClassVersionError in MinecraftUnsupportedClassVersionError means Minecraft or a mod needs a newer Java than the one running it. See which Java each version needs and how to check yours.
- How to find your Minecraft logsFind latest.log and crash reports for the Minecraft client, servers and launchers like Prism and Modrinth App. Paths for Windows, macOS and Linux.