This probably doesn't even need to be asked, but I want to make sure that I'm right. When you create an array of any object in Java, for example:
Object[] objArr = new Object[10];
The objArr variable is on the memory stack and points to the place on the heap where the array object is located. The size of this array on the heap is equal to the 12-byte object header + 4 (or 8, depending on the reference size) bytes * the number of entries in the array. That's for sure?
So my question is this. Since the array above is empty, does it occupy 12 + 4 * 10 = 52 bytes of memory on the heap immediately after this line of code is executed? Or does the JVM wait until you start putting things into an array before it creates it? Are null references in the array taking up space?
brenns10
source share