CustomNPCs MarkData Leak Fix
Fixes a CustomNPCs-Unofficial memory leak that keeps every unloaded mob in memory and crashes servers with OutOfMemoryError.
介绍
CustomNPCs MarkData Leak Fix
Fixes a memory leak in CustomNPCs-Unofficial (NeoForge 1.21.1) that can crash your server with OutOfMemoryError.
This is an unofficial fix by a third party. It is not part of CustomNPCs and has no affiliation with its authors.
Do I need this?
If you run CustomNPCs-Unofficial on NeoForge 1.21.1, yes, especially on a server.
The symptoms look like this:
- Memory use climbs for days, even with nobody online.
- Lag builds up over hours ("Can’t keep up!"), and then the server crashes with
java.lang.OutOfMemoryError: Java heap space, or the watchdog kills it. - It’s at its worst while pre-generating the world (Chunky and similar) or while players explore new land. We measured about 1 GB of heap per hour during a pregen.
What’s wrong
CustomNPCs keeps an internal cache of "mark" data for living entities. It adds an entry every time a mob is saved, which happens on every chunk unload and every autosave, and every time a mob is shown to a player. It never removes one. Each entry holds on to the whole mob, including its AI, attributes and every other mod’s data on it, so unloaded mobs can never be freed.
We found it on a 31 GB server that kept crashing during a pregen. A heap dump showed about 53,000 mobs in memory while only about 500 chunks were loaded, and every one of them was held by that cache.
What this mod does
- It makes the cache thread-safe. CustomNPCs uses it from several threads without locking.
- It drops an entry once its mob has left the world: unloaded, killed, or changed dimension. A check every 10 seconds catches anything else.
Nothing CustomNPCs could still use is lost. A mob that comes back gets a new ID and a new entry anyway. Entries for mobs that are still loaded are never touched, so their marks stay put.
Details
- Server, client or both. Clients leak the same way, just more slowly. Install it on both if you can.
- No configuration. Drop it in
mods/. - Safe without CustomNPCs: it does nothing.
/cnpcmarkfix(op level 2) shows the status, how many mobs are cached right now, and how many have been released.- Tested with CustomNPCs-Unofficial
1.21.1.20251230on NeoForge21.1.247.
Tested
This was checked on a headless NeoForge test server with the real CustomNPCs jar. 200 cows were unloaded the normal way:
| unloaded mobs still in memory | marked mob that stays loaded | |
|---|---|---|
| CustomNPCs alone | 201 of 201 | kept |
| with this fix | 0 | kept, mark intact |
Note for CustomNPCs users
While testing, we noticed that this CustomNPCs build doesn’t save marks into the mob’s save data. A mark on a mob is lost once that mob unloads, with or without this fix. That’s CustomNPCs’ own behaviour, and this mod doesn’t change it.
License
MIT. Source code: see the GitHub link on this page. This mod contains no CustomNPCs code; it adjusts the cache at runtime.
常见问题
CustomNPCs MarkData Leak Fix 支持哪些 Minecraft 版本?
CustomNPCs MarkData Leak Fix 支持 Minecraft Java 版 1.21.1,可用的加载器:NeoForge。下载时注意选择和你游戏版本一致的文件。
CustomNPCs MarkData Leak Fix 怎么安装?
先用 PCL2 或 HMCL 启动器安装对应版本的 NeoForge,再把下载的 .jar 文件放进游戏目录的 mods 文件夹,重新启动游戏即可。开启了版本隔离的,mods 文件夹在 versions/版本名 下面。
DepthDrako 的其他作品
查看全部 →Create: The Bots Foundry
Welcome to this first mod to bring the fell of a triple A title to minecraft.
Botz Mob Leveling
Configurable mob leveling for Forge 1.20.1. Mobs scale by distance from spawn, structures, and datapack rules.
The Silver Dragon Adventure 2
A mod pack to allow you to do what ever you want
Create Magica – The Battle For Eldolon Reach
A Modpack With Crazy fights and amazing factories. But with the subtle sweetness for that partner in your life.
评论
登录后评论和评分