Version: ModelEngine R4.1.1 (com.ticxo.modelengine.v26_2), Paper 26.2-135, Java 25
Setup: Another plugin creates and unloads temporary worlds all the time (dungeon instances, one world per run).
What happens
While analyzing a heap dump taken on OutOfMemoryError, I found that one unloaded world (a dungeon instance unloaded several hours earlier) was still strongly reachable through ModelEngine:
ModelEngine (plugin) .nmsHandler
-> com.ticxo.modelengine.v26_2.NMSHandler_v26_2 .entityHandler
-> com.ticxo.modelengine.v26_2.entity.EntityHandlerImpl .dummyArmorStand
-> net.minecraft.world.entity.decoration.ArmorStand .level
-> ServerLevel (unloaded world, with all its chunks)
Cause
In EntityHandlerImpl.movePassenger(Entity, double, double, double), the dummy armor stand is created lazily from the level of whatever passenger is moved first:
if (dummyArmorStand == null) {
dummyArmorStand = new ArmorStand(EntityTypes.ARMOR_STAND, nmsEntity.level());
dummyArmorStand.setMarker(true);
}
It is never replaced afterwards. If that first passenger was in a temporary world, the armor stand's level field pins that whole ServerLevel for the rest of the server's uptime.
This is only one world, so it's a fixed cost rather than ever-growing. But it is still a whole world with its loaded chunks, and it shows up as a leak in every heap dump, which makes it harder to find the real growing leaks.
Suggested fix
Any of these would work:
- Create the dummy armor stand in
MinecraftServer.overworld(), which is never unloaded. The same class already usesoverworld()ingetNextEntityId(). It is only used forgetVehicleAttachmentPoint, so the world doesn't matter. - Or create it per call, or recreate it when
nmsEntity.level() != dummyArmorStand.level(). - Or clear it on
WorldUnloadEventwhen its level is the world being unloaded.