Uploaded image for project: 'Spigot'
  1. Spigot
  2. SPIGOT-4549

Metadata of Entities gets leaked by default


    • Icon: New Feature New Feature
    • Resolution: Duplicate
    • Icon: Minor Minor
    • None
    • None
    • Tested on Windows 10 and Ubuntu 18.04. As far as I know, environment doesn't really matter though, as it's an API design choice

    •  This server is running CraftBukkit version git-Spigot-573cdf2-dff66df (MC: 1.13.2) (Implementing API version 1.13.2-R0.1-SNAPSHOT)
    • Yes

      Currently, when you spawn an Entity, attach some metadata using `Entity.setMetadata(key, metadata)` and remove an entity (it doesn't really matter when the remove happens), the metadata stays into memory indefinitively. 

      I found this example that perfectly demonstrates this problem:


      As you could guess with the current design, this would mean that you either:

      • Have to manage the metadata yourself too in order to clean it up (and prevent a memory leak). This would require you to track all metadatables where you attach metadata too.
      • Make it easier to delete the metadata.

      One way I though of was that if we could listen for an event in the likes of for example EntityRemovalEvent, in which we can cleanup all metadata. This way it would not break old implementations, if they for some reason would build upon the memory-leaking behavior, yet it would allow new/maintained plugins to handle the possible memory leak more easily.

            Unassigned Unassigned
            KoekenMeneer KoekenMeneer
            0 Vote for this issue
            0 Start watching this issue