Potential memory leak due to peripherals
Paspartout opened this issue ยท 2 comments
Hello,
I am managing a Valhelsia 3 server which has CC:Tweaked in it.
We recently ran into memory problems and we suspect CC:Tweaked causing the issue.
What leads to this conclusion are the following heapsummaries we did(you can filter by typing dan200 in the top right text box):
After running for 1hour: https://spark.lucko.me/#zbrZ9rYWNE
After running for 1.5hours: https://spark.lucko.me/#e2I9PBEtm2
After running 12 hours: https://spark.lucko.me/#zbrZ9rYWNE
As you can see the number of SaturatedMethod
and GenericPeripheral
, among other class instances are increasing.
I looked at every computer on the server and could not find anything special.
Most of them are connected to screens, floppy drives and ender wireless transcievers.
Some of the chunks are chunkloaded by other mods but no setup or peripheral was crossing chunk borders.
The only way to narrow down the issue is probably to disable chunkloading and loading or visiting every computer setup in isolation. I could not reproduce the leak yet by placing computers in chunkloaded areas in a test world.
Maybe you got a hint to what to look at? Thanks!
Useful information to include:
- Minecraft version: 1.16.4
- CC: Tweaked version: cc-tweaked-1.16.4-1.94.0.jar
Oh yikes, this isn't good. I suspect this is caused by us adding listeners to adjacent capabilities:
These are never removed (Forge doesn't have such a system), and so if peripherals are recomputed, we get a leak. I imagine this can be reproduced by placing down a trapped chest next to a computer and opening/closing it. I'll try to look into this further tonight.
I'm not 100% sure how best to fix this. I imagine we're going to need to make peripheral providers stateful, so we can attempt to reuse as much state as possible from the previous peripheral. Ughr, this is not pleasant at all.