Got a question: Clearing Lists/Arrays - is it helpful?

Pretty straight forward question and not a lot to write here.

If I use Lists/Arrays that aren’t actively executing after Awake/Start – do they need to be cleared? Could it be detrimental to performance on larger projects?

For example in my procedural item creation I have a list of EStats that live on the Base Item Assets that upon Awake() will run once that goes through said EStat List - for the purpose of creating randomized modifiers to add to the item.

After enumerating over this once, that List of EStats is virtually doing nothing – the EStat list remains populated with information it’s no longer using.

So, Is that something to be mindful about when using tonnes of Lists/Arrays if they’re not cleared?

A lot depends on the context…
I’m assuming snce we’re talking about stats and modifiers, that this is an InventoryItem, which is a ScriptableObject.
If you are instancing the ScriptableObject (i.e. creating a copy at runtime), then yes, you’ll probably be saving heap space.
If you’re working on the ScriptableObject directly, then I’m not entirely sure.

Yeah in this particular scenario it’s pertaining to the StatsEquipableItem → InventoryItem which as you mentioned is a scriptable object.

I wanted to Initialize modifiers based on chance similarly to how you do it, of course we all take different approaches – I ended up doing a foreach within a potentialModifier list of EStats and then rolling a dice to add it to the additive or percentage modifiers.

But this method I’ve taken means that the item themselves will carry a list of EStats that I can use design wise to allow certain stats be exclusive to particular items based on my game design choices.

Anyways, I was just a bit concerned if that all adds up to garbage collection if there’s 100’s of items with lists of EStats that they carry excessively after they were initially instantiated which has no purpose outside of the Awake() phase.

I think this is a case where you’re only going to know for sure if you profile it.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms