mojira.dev
MC-301114

Memory leak when an entity is frequently damaged

When an entity is damaged, a CombatEntry is created in CombatTracker.entries.

Every second the CombatTracker.entries will be cleared if the entity is dead or wasn’t damaged during the last 100 ticks (300 ticks if entity was recently attacked).
The problem: If an entity takes damage frequently with less than 100 ticks between the damages, new entries are added to the list and the list won't be cleared, causing a memory leak

Linked issues

Attachments

Comments 3

I was unable to reproduce this with the following setup:

  1. Create a new void superflat world

  2. /fill -2 -59 -2 2 -59 2 lime_stained_glass

  3. /teleport @s 0 -58 0

  4. /gamerule commandBlockOutput false

  5. Build the following on the glass, where the repeaters are all set to 4 (redstone) ticks and the command block has execute positioned 0 -61 0 as @e[type=sheep] run damage @s 0 minecraft:mob_attack by @e[type=minecraft:armor_stand,limit=1,sort=random]

    2025-08-16_12.07.16.png
  6. /fill -31 -61 -31 31 -61 31 stone_brick_wall

  7. /fill -30 -61 -30 30 -61 30 air

  8. /fill -30 -62 -30 30 -62 30 minecraft:dispenser[facing=up]{Items:[{id:"sheep_spawn_egg",components:{"minecraft:entity_data":{id:"minecraft:sheep",NoAI:1b}}}]}

  9. /fill -30 -63 -30 30 -63 30 minecraft:redstone_block

  10. /summon minecraft:armor_stand -31 -59 0

  11. /summon minecraft:armor_stand 31 -59 0

  12. /summon minecraft:armor_stand 0 -59 -31

  13. /summon minecraft:armor_stand 0 -59 31
    Your setup will now look like this:

    2025-08-16_12.44.00.png
  14. Press the button

  15. Observe memory usage in F3 menu or system software

Enabling AI on the sheep and increasing the number of sheep affected did not help.

Please provide reproduction steps that demonstrate a meaningful memory impact caused by this issue. This report will be automatically reopened when you reply.

You won't notice it until you let it run for several days. The memory leak is gradual.

In that case I will set this issue to Plausible. Most likely Mojang will call it either Won’t Fix or Low priority.

ErfinderLabyrinth

(Unassigned)

Plausible

Platform

Normal

Performance

1.21.8

Retrieved