Solved How Expensive is an Inventory?

Discussion in 'Spigot Plugin Development' started by Varmetek, Jun 5, 2017.

  1. I'm currently working on a project where I need to process large amounts of items before they enter a player's inventory. I thought about creating an Inventory of each processing routine but then I wonder if that practice is really efficient.
    If I decided to use this method, how expensive is creating an Inventory and would I have to worry about memory leaks?
  2. You should be fine, I'm working on a large project with about 10-15 Inventories. It's like breathing for the server. Only thing I could think of causing a memory leak in this case is if you make it static. Memory Leaks happen because static doesn't end after the task, it stays with the process until it closes, aka onDisable. So avoid static and you should be good.
    Edit: Remember, the inventory is virtually the same thing as a Chest, but no block/holder.
    • Agree Agree x 1
  3. Therefore it should be fine if I create multiple inventories a minute and never reference them again. Right?
  4. As long as they aren't static, as mentioned above, I don't see an obvious issue.
  5. I mean, you could just skip the inventories entirely and hold an array/collection of items yourself.
    • Agree Agree x 1
  6. Agree with that a lot. Then you could use the java 8 stream api for handling the processes. And your program has to save less data, no title or owner or size, and that is always better, how small it may look.
  7. Thank you for the responses. Marking as solved.