Solved Storing player objects in a map or collection or w/e

Discussion in 'Plugin Development' started by vidhu, Jul 17, 2013.

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


    So around the bukkit dev community, people are saying "DO NOT store player objects in a collection because it leads to memory leaks..." and then it is usually, actually always followed by an example of:
    1. Player logs in
    2. Player object is stored
    3. Player quits game
    4. Garbage collection wont remove the player object as it is referenced in your collection

    BUT how about you remove the player object when the player leaves the game? will something else cause mem leaks?
  2. Offline


    Why would ever need to store player objects? vidhu
  3. Offline


    ... dont ask y. Please answer the question if you can
  4. NEVER store Player objects in Maps.
    Someone of the Devs said that in his Posts.

    Store their Name as String and then get their Player Object, if it still exists.

    mxbaxter postet it in
  5. If the object is properly removed then it shouldn't cause any memory leaks, however problems in code or maybe even mc bugs could cause the player to not be removed from the list. Since there is no downside to storing a string it's always best to just store that instead, there's no point in making things more difficult than necessary.
    But yes, removing the player object from the list should prevent memory leaks
    vidhu likes this.
  6. Offline


    thanks! that is the answer i was looking for!
  7. Offline


    Pretty much every piece of advice on here, including my own, should be taken with a pinch of salt. It's all about experience and understanding exactly what you are doing.
Thread Status:
Not open for further replies.

Share This Page