The question is answered, right answer was accepted
Does empty array declaration take memory?
I have a large "Monster Manager" script, wich has lot of public arrays (all empty) If I select an enumerator like "Shoot", I have to use the Bullets array (gameobject). The script uses coroutines based on the enumerator, it won't check something from other arrays.
So my queston is, do i kill my game doing this way ? Because my game will have lot of monster each scene, but each monsters has a lot of empty arrays. They're all empy and their size won't be changed in the script, so does unity consider them in memory or not?
If they do, how much can they take? And if you want to leave them null to save space, ask yourself if checking for null all the time is more of a waste.
Google "premature optimization" for why you shouldn't even worry about this.
Thank you, but I already have my game. I have the full "master" script but I have lot of empty arrays, and I don't know how Unity handles them.
Arrays will take up space for the references at least, even if empty. But you really shouldn't worry about this because even if you have 1000 references it will only use up like 4 kilobytes.
Answer by JedBeryll · Sep 17, 2016 at 02:30 PM
Arrays will take up space for the references at least, even if empty. But you really shouldn't worry about this because even if you have 1000 references it will only use up like 4 kilobytes.
?? I'm not reading that as the Q. Obviously int[] A=null; takes some space. But does int[] A=new int[0]; take more? But, of course, the correct answer is as you write: not enough to be worth thinking about.