mojira.dev
MC-298464

Memory leak in hoglin farm due to CHANGED_DIMENSION entity removal

Memory Leak in Hoglin Farm (VisualVM Analysis, Fig. 1)
A memory leak has been identified in a Hoglin farm (Fig. 2) in Minecraft 1.21.5. The farm was built in the crimson_forest biome and relies on despawning Hoglins in the Overworld when no player is within 128 blocks.

The issue also reproduces in earlier versions with a similar farm design (Fig. 3), as reported by Cupperum29 and marcogao.

Root Cause Hypothesis:
This appears to be a special case of entity retention when Hoglins are removed due to CHANGED_DIMENSION, referencing

MC-260605

Attachments

Comments 2

possibly related
https://raw.githubusercontent.com/Winds-Studio/Leaf/2f72924ec7b24b8574ba50470b4217af96bf9452/leaf-server/minecraft-patches/features/0275-fix-MC-298464.patch

public class CombatTracker {
    private final List<CombatEntry> entries = Lists.newArrayList();
}

public record CombatEntry(DamageSource source, float damage, @Nullable FallLocation fallLocation, float fallDistance) {
}

public class DamageSource {
    private final Holder<DamageType> type;
    private final Entity causingEntity;
    private final Entity directEntity;
    private final Vec3 damageSourcePosition;
}

public abstract class LivingEntity extends Entity implements Attackable, WaypointTransmitter {
    public void remove(Entity.RemovalReason removalReason) {
        if ((removalReason == Entity.RemovalReason.KILLED || removalReason == Entity.RemovalReason.DISCARDED)
            && this.level() instanceof ServerLevel serverLevel) {
            this.triggerOnDeathMobEffects(serverLevel, removalReason);
        }

        super.remove(removalReason);
        this.brain.clearMemories();
        // leak CombatTracker#entries ?
    }
}

Hello @wulongcha , thank you for the detailed bug report and analysis!
I’m wondering if it would be possible for you to upload the world save with that Hoglin farm?

wulongcha

Nathan Wolf

Plausible

Platform HC

Important

Entities, Performance

1.21.5

Retrieved