Plugin leaking player objects

Discussion in 'Plugin Development' started by ShakyTom, Feb 12, 2013.

Thread Status:
Not open for further replies.
  1. Offline


    Hello there!

    After around 8 hours of uptime I have noticed that I have about 1.5k player objects even though my player count is around 250.

    What would cause a plugin to create player objects that are not destroyed?

  2. Offline


    Adding a Player instance to an ArrayList, HashMap, HashSet etc without removing it on logout, that will create memory leaks
    zack6849 and microgeek like this.
  3. Offline


    Use the player name it's much better. Also above post is one main reasons
  4. Offline


    When a player reconnects Craftbukkit / Minecraft creates a new Player object, it doesn't use the previous one. So if you're storing player objects you should make sure to remove them after a logout.

    It's possible that you don't want to remove them immediately, but this can be problematic if a player reconnects before you have removed its previous object. In that case the idea is to compare the name of the player with the names of your old Player objects, and to replace them if needed.

    As you can see storing Player objects can lead to some issues when not done correctly. You should use OfflinePlayer objects (which doesn't mean that the player is necessarily offline, the name is misleading) when possible.
  5. Offline


    Thanks for the help guys - Now to find which one of my plugins is the cause!

    Is there any easier way than checking the source of them?

    Edit: Found it, was a hashmap storing Player objects.
  6. Offline


    Hmm, not really.... start with the small plugins and work your way up, you only need to look for fields.
    If you use JDGui you can use search (ctrl+shift+s) for *Player and leave only Type checked there, it should limit your search.
Thread Status:
Not open for further replies.

Share This Page