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

Metadata of Entities gets leaked by default

XMLWordPrintable

    • 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:

      https://gist.github.com/forairan/6e0e36be6c95632d7a85

      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
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: