How much memory does an array of null gameobjects use?

if i have GameObject[] gameObjects = new GameObject[100]

how much memory does each element use without being assigned to anything?

Remember that code runs on specific target hardware architectures.

What architecture you target makes a huge difference.

In a 64-bit system it will likely be 8 bytes per reference item in the array, plus some extra object overhead for the array, I imagine not that much.

If GameObject were a struct (it’s not!), then space would be allocated for each one, since structs (value types) are not nullable.

You can always attach the profiler and see for yourself on each target: Window β†’ Analysis β†’ Profiler

2 Likes

8 bytes per reference in 64 bit
4 bytes per reference in 32 bit.

That particular example you posted would be 800 bytes in 64 bit and 400 bytes in 32 bit.

This will not change when you assign elements to the array. The size of the array itself remains the same. The objects it refers to will take up their own memory separately of course.

2 Likes

okay thanks