mojira.dev
MC-270896

Players leak the last entity they took damage from

Players leak the last entity they took damage from and can keep long chain of unloaded entities and worlds in the memory until they are damaged again. For example player A takes damage from enderman in the end and then they damage player B in the overworld. Finally they end up changing their dimension to the nether and disconnect. Now player B keeps the reference to player A alive, which also roots the long gone enderman.

This seems to be due to the field lastDamageSource in LivingEntity which is never cleared unless the getLastDamageSource method is called and 40 ticks has passed since the damage was taken. The fix would be to move this to be part of the tick procedure.

Linked issues

Comments 1

Can confirm in 26.3, code analysis:

public DamageSource getLastDamageSource(int maxAge) {
    return level().getGameTime() - lastDamageStamp > maxAge
        ? null
        : lastDamageSource;
}

private final Entity causingEntity;
private final Entity directEntity;

I would like to point out that the report’s description is outdated because in 26.3, even calling getLastDamageSource after 40 ticks does not clear the field. It only returns null.

isokissa3

(Unassigned)

Community Consensus

Platform

Normal

Entities, Performance

1.20.4, 1.20.5 Release Candidate 1, 26.3

Retrieved