In this post I will describe how to search for memory leaks in your bukkit minecraft SMP server.
Getting a heap dump
The first step is to obtain a java heap dump to inspect. This is a nice article on the subject:
However none of those tools work well together with bukkit. The tool jmap hangs the minecraft server and then crashes it. The tool hprof makes the server slow down to a crawl.
So we are going to use another method. We will instruct java to dump the heap if the application (bukkit) runs out of memory. We do this by passing some additional arguments when starting the server:
Your command could now look like this:
java -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/tmp -Xms3G -Xmx3G -jar craftbukkit-0.0.1-SNAPSHOT.jar
Now you should run your server till it crashes. The out of memory errors on my server looks something like this:
java.lang.OutOfMemoryError: GC overhead limit exceeded
And after the crash I have a file named “/tmp/java_pid1577.hprof”. This is the heap dump we want to analyze. In order to do that I transfer it to my desktop computer using FileZilla. You would might want to compress the file before you transfer it. My file was 2.5 gigabytes so I compressed it to 186 megabytes before transfering it (6% compressions ratio :O)
gzip -9 java_pid1577.hprof
Analyzing the heap dump
You can now download this heap dump to your own computer and analyze it. Here are some nice free tools for doing just that: