PowerNukkit stops responding and crash with OutOfMemoryError: Java heap space

Symptoms

  • The server starts to have lag spikes that increasingly more time to recover each time.
  • The server stops responding for a long period and may get killed by the Watchdog
  • The message OutOfMemoryError: Java heap space is logged in the console and the server log files.

Possible Causes

  • You contracted a Minecraft hosting plan that provides you a Multicraft or similar panel but the amount of RAM in your plan is too low for the number of plugins, loaded chunks, worlds, entities, or online players that you are trying to use
  • The server JVM memory is too low or too high
  • Other programs that are running concurrently are using too much RAM
  • You are using a 32-bit JVM distribution instead of 64-bit
  • You are using a 32-bit operating system

Resolution

Request more memory

If your hosting plan only provides you a control panel to manage your server, similar to the one below, you should request support for your hosting provider. Your server might be running in a managed environment that you might not have much control other than changing the world, changing the JAR file, and installing plugins.

Allocate more RAM for the Java process

To increase the maximum amount of RAM that can be used by your server you need to start the server with the -Xmx[amount][G/M] param, to allocate 4.5 Gigabytes of RAM to the server you should run:

java -Xmx4.5G -jar powernukkit.jar

The -Xmx param must be before the -jar param. Don’t allocate too much, leave some RAM for your operating system and background process too or you may also have

Upgrade to Java 8 64-bit

Make sure you are using Java 8 64-bit by running this command in the terminal:

java -d64 -version

You should receive a message similar to the output below if you have a 64-bit JVM:

openjdk version "1.8.0_252"
OpenJDK Runtime Environment (build 1.8.0_252-b09)
OpenJDK 64-Bit Server VM (build 25.252-b09, mixed mode)

But if you receive a message similar to this other output, then you don’t have Java 64-bit set as your main JVM.

Error: This Java instance does not support a 64-bit JVM.
Please install the desired version.

You can download Java 8 64-bit from the link below, but your system also needs to be 64 bit. It may require a free Oracle account to download the file.
https://www.oracle.com/br/java/technologies/javase/javase-jdk8-downloads.html

You may also use a package manager to install it automatically, like yum, apt, pacman for Linux and Chocolatey

But before upgrading, check if your system is 64-bit. You can’t run Java 64-bit in a 32-bit operating system.

Linux

To check if a Linux system is 64-bit, open the system terminal and run this command:

arch

If you are running a 64-bit system it should output x86_64

Windows

Press Win+R, type cmd and press Enter

Run this command to know if your system is 64-bit:

wmic os get osarchitecture

You should see an output like:

OSArchitecture
64-bit

Low System RAM

Solution 1: Close other programs

Close programs that could be using too much RAM, move them to another server, or adjust their memory usage.

Solution 2: Decrease the Xmx value

If you can’t leave make more RAM available in the system, and you observe high memory usage over time. Reduce the amount of RAM that is allocated to the server until you find a balance.

32-bit Operating System

32-bit systems have a limited amount of RAM available, you should ask your hosting provider to migrate to a 64-bit system so you can increase the RAM as you need.

Workarounds

If you can’t afford more RAM or a 64-bit system, you have the following options:

Reduce the view-distance

Open the server.properties file and reduce the view-distance to reduce memory usage.

Disable chuck-cache

Open nukkit.yml and disable cache-chunks to reduce memory usage.