Memory wasting question

Discussion in 'General Help' started by RcExtract, Aug 4, 2017.

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

    RcExtract

    Does saving a player instance or a player uuid use up more memory? Does Java save the memory location of the instance into the variable, or the player instance?
     
  2. @RcExtract
    It's not worth worrying about. The difference is so miniscule that it really doesn't matter. Do what makes sense from the perspective of writing the code (which will probably be the UUID.

    If you're looking for an answer just for theoretical reasons, I'm pretty sure it would be the same amount of memory used, since both objects would be stored elsewhere in memory. All the local variable would be doing is pointing to that memory space that is already in use by minecraft and CraftBukkit internals.
     
  3. Offline

    Zombie_Striker

    @AlvinB @RcExtract
    Java only saves memory locations for variables. If you properly clear out the player's instance when they leave, then you should not have to worry about space.

    However, if you still store the player's instance after the player leaves, then that is a problem. In that case, you are creating a memory leak. The instance of the player is being stored in memory even though you should no longer have any access to it. This is why we normally recommend using UUIDs for storing the player, as it is better to keep a small string in memory compared to all the properties of a player.
     
  4. @Zombie_Striker
    The UUIDs being more efficient is only true if the player is offline, if the player is online, both methods would use objects already stored in memory, making the variable just reference those.

    Also, UUIDs are stored as numbers (two longs if memory serves me), not Strings. Strings would be a lot more inefficient, since you'd have to have to have one byte (or more, depending on encoding) per character.
     
    Zombie_Striker likes this.
Thread Status:
Not open for further replies.

Share This Page