I'm creating the main inventory for my project and I'm starting to have some doubts about how to manage the objects. Right now there's three tabs: Inventory, Wish list and a Collection tab.All of these have their scenes with animated sprites panels and whatnot.Right now the inventory menu is created once the inventory is opened, I create not just the default tab but all the other tabs objects and then I just simple hide and show the current tab. I was wonder if it's better to have it always loaded or on the other hand if It could be better to create and destroy the objects of the tabs as they are opened and destroy them once the tab is changed.

For what I understand is a trade between cpu and memory, create requires more cpu process time and hiding requires memory. I would like to read if you have any rule you like to follow about when to chose one over the other, maybe you hide UI elements without logic but destroy complex entities?

Are you experiencing performance issues? If not, don't worry about it. Both CPU and RAM that would be used in either case I can imagine would be minimal.

That said, since you were asking for personal opinions on the matter I generally follow this rule (very loosely):

If the user or system needs to access something immediately without warning, keep it in memory if possible. If a delay is acceptable or usage is predictable then load it on demand.

Honestly, just take a look at your profiler and monitor in the debugger. It tells you how CPU intensive something is as well as how much memory is being used. You can decide what to do from there.

I'm not experiencing performance issues but I have come across them and solved unintentionally which is the worst kind of solution so maybe it's not about the method but my code repeating loops or something. I'm new to these things so I can't imagine how heavy it'll be once everything is loaded. There's much to learn so I didn't read much about the profiler and how to debug for now all I do is print when searching for bugs.

@Binsk said: Are you experiencing performance issues? If not, don't worry about it. Both CPU and RAM that would be used in either case I can imagine would be minimal.

+1 on this. If you are not experiencing any issues, then whatever is the most comfortable/easy/future-proof solution you have is probably fine. If it starts causing issues, you will likely need to refactor and rewrite the code anyway to a solution that is fine tuned to your particular use case. Its very hard to prematurely optimize in a way that yields benefits in the long run.


Personally, for things like UI, I generally just show/hide them. If I have elements that are dynamic (like an inventory), I will generally spawn and delete them when showing and hiding the UI, as I find its easier to manage a clean slate each time rather than seeing what in the dynamic stuff needs to change. Outside of that though, I generally just go for a simple solution and show/hide things.

2 years later