
Folia server memory leak
Closed this issue ยท 15 comments
What steps will reproduce the problem?
Towy had a very serious memory leak in the Folia server, consuming 120GB of memory in 12 hours
Here is a JProfiler analysis of some spark memory dump heaps that may have memory leaks




What is the expected output?
Fix these memory leaks that exist because he keeps my server from running for a long time
Towny version
Actions towny-0.101.2.1
Server version
Folia 1.21.8
Please use Pastebin.com to link the following files
- Your full server startup from the logs\latest.log:
- Your Towny config.yml:
- Your townyperms.yml:
- Your log's error:
(optional) If this is to do with permissions,
5. Your permissions file:
(optional) If this is to do with chat,
6. Your chatconfig.yml:
7. Your channels.yml:
In the current analysis, it may be related to the physical protection of the towny, and the shulker farm in the towny will accumulate in large quantities due to the inability to clear the task due to the entity protection
We use folia's scheduling API to schedule a task per entity to check for despawning, and rely on the server to clean up these tasks upon the entity unloading, are you still using luminol or actual folia 1.21.8? Having a full log and config might also help.
Yes, I'm using the Luminol branch, I've communicated with the author of the Luminol branch, earthme, who hasn't been able to analyze the specific reason yet, but you can also see from the memory dump that towny still has some questions, if you want other logs, I can find a way to provide it to you
In fact, I discovered this problem yesterday, yesterday it was an iron golem mission that caused the accumulation of 54.5 million instances and caused a memory leak, my approach was to remove Towny's protection of NPCs and did not find a memory leak caused by the iron golem
If you could reproduce this issue on folia first of all then that would be nice, I've looked at heap dumps of my own and have not seen such things happening. The server software is responsible for retiring the scheduler upon the entity being removed, if the tasks are sticking around in memory exclusively on luminol then that would point to something being wrong there.
Okay, I will provide a test report of the native Folia in the next few days, but this may take a while, during which time I will continue to communicate with the luminol author and analyze the specific problem in depth
Memory leaks are also currently occurring in the tests of native Folia, and I'll give you a detailed heap dump analysis when I run out of memory in a day
He consumed 30GB of running memory in just 4 hours of launch, but according to my tests, this problem is magnified on Windows Server systems
Because the memory consumption is not so exaggerated in my other Linux server, but I can't swap my windows server for Linux right now, because it has a lot of important services
In the native Folia, the towny plugin is still leaking a lot of memory
You can see the source of the leak of this dump heap that I gave you in Luminol before, I have encountered a total of memory leaks caused by iron golems, shulkers and other creatures, indicating that there is indeed a problem with the task cleaning of the plugin, as well as a bug in the territory protection function and territory deletion function

Thanks for double checking for me, I can see the same thing happening in a heap dump of my own now which means I can investigate.
I've pushed a branch that cuts down on the number of objects being allocated in an effort to try and fix this issue, you can download it from here (downloads as a zip).
Please try this build to see if it fixes your issue, I tried to reproduce this issue locally for a few hours but had no luck doing so unfortunately.
Thanks to the author for finding the same problem, which also facilitates our continuous tracking of bugs, I will spend a few days to determine if the latest branch has the same memory leak, please wait for my test results