#World Unloading Memory Leak

1 messages · Page 1 of 1 (latest)

muted urchin
#

It so happens that when I unload a world with Bukkit#unloadWorld(World, boolean) (save is set to true), there is a memory leak (i.e. no memory being freed, going as far as using an extra GB of ram with only unloading 10 worlds), this is a simple test plugin, all it does it create 10 new worlds and unload them, fresh server, is this known?

frank stag
#

Sounds like you are holding references to the worlds still

sharp valve
#

or not waiting long enough for a good GC

muted urchin
#

I have been waiting for 10 minutes for it to clear

#

also let me send what I'm doing

#

nope, all I do is the following:

var worlds = new ArrayList<World>();

for(int i = 0; i < 10; i++) {
  worlds.add(new WorldCreator("world_" + i).createWorld());
}

for(var world : worlds) {
  Bukkit.unloadWorld(world, true);
}

worlds.clear();
#

In a command*

#

It went from 2.38GB of ram to 3.19GB of ram just by doing that

sharp valve
#

what heap flags do you have on your java?

muted urchin
#

java -Xms128M -XX:MaxRAMPercentage=95.0 -Dterminal.jline=false -Dterminal.ansi=true -jar server.jar & docker image is ghcr.io/software-noob/pterodactyl-images:java_19_zulu

#

*Running on ptero

sharp valve
#

I don;t know the max ram setting there

muted urchin
#

The MaxRAMPercentage parameter allows setting the maximum heap size for a JVM running with a large amount of memory

sharp valve
#

you could try using MaxHeapFreeRatio

#

depending on what GC it's using it may not want to free up heap

muted urchin
#

I can try using ZGC

#

That worsens the problem, so I don't think it's an issue with the GC itself

upper dune
#

world unloading is fundamentally flawed in bukkit (or minecraft?). You can do everything right and there will still be memory leaks with them that noone seems to want to fix.

sharp valve
#

Yeah, if ZGC doesn;t want to let it go then it's not free.

muted urchin
#

yep, for example ServerChunkCache#purgeUnload is never called, and even then that still holds quite a bit of memory through allocated arrays, and I believe some more fields are not closed in the ServerLevel

upper dune
#

On our server we can have hundreds of games a day, where we create and unload worlds, we do everything right and there are no references to the worlds yet some chunks or some other metadata still seem to remain in memory. The leak is slow enough that it doesn't become a problem unless we don't restart for a couple days though.

muted urchin
#

fyi holding players/entities still causes the world to be loaded, but yeah no this shit is insane

upper dune
#

I've looked at loads of heap dumps and gave up in the end

muted urchin
#

We're running into an issue in our server were we create and delete dozens of worlds even per minute and the OOM Killer is having a field day

#

@upper dune mind sharing if you found anything w/ improving this issue

upper dune
#

make sure the created worlds have keep spawn loaded disabled, keepspawninmemory disabled, enable autosave for those worlds, and pass true to the boolean in unloadWorld

#

considering how many worlds you're doing though... I think you will have to look into patching the server to fix the problem which is going to be awful to try and do (and if you're on Paper then you have to deal with the rewritten chunk system)

muted urchin
#

@upper dune I found the issue, some stuff isn't being cleared up, I'm looking into it and maybe I'll be able to make a PR to fix it

upper dune
#

I hope so

upper dune
#

@muted urchin did you get anywhere with this? is it problems specific to paper / spigot or vanilla?

muted urchin
#

It's a problem in vanilla, we're debugging this but it is a nightmare, we found the root cause and are working on a fix atm

#

Will make a PR within the week