There are several quite big static arrays in the different place of code. For example such as:
public static someIndexes = new int[1024, 1024];
There is no references on one of them at all. It just not used. Will it be excluded from the final build? Or it will be created in memory at launch anyway?
Most compilers will remove statements without side effects in the optimization stage. Mono is no different AFAIK. If you have unused variables they will most likely be trimmed.
Another example is loops with nothing in them or modifying a variable that is never used. They will simply be removed and replaced with an “Identity”. You can play with a C compiler and look at its generated assembly if you want an idea of what a compiler will do for you.
I just did a simple test. Creating it as big as possible.
At first, and in my case, using either nothing or [9999][9999] would yield to no difference. Even the profiler showed nothing. Going 1 higher to [99990][99990] already proved to be no good. Can’t even compile. Say “OutOfMemoryException: Out of memory”. I created it as such:
public class Test : MonoBehaviour {
static int[,] bigVar = new int[9999,9999];
}
Then I deduced that, as expected, it is created even if not being used. If you can pass through the initialization, no difference is noticed because it’s not being used. But, as it turns out, it’s not that simple.
On a second test, thanks to @MorphingDragon’s insight, there was no error at all. No matter how big I set it:
public class Test : MonoBehaviour {
static int[,] bigVar;
void Start () {
bigVar = new int[999999,999999];
}
}
Garbage collector only acts at run time (and I thought it would not touch static variables, but I was wrong there). The compiler couldn’t filter it out at first, even if not being used, most likely because of how it was initiated (don’t ask me why).
So, just initiate it on Start or Awake and you’ll be fine!