Inventory system not working properly.

Where do you think I should clear the array? Whenever the inventory is open or whenever it is built, sorry for the stupid questions im new to the game development scene