JVM中Circle数组初始化内存分配计算的正确性求证
Circle[] myCircleList = new Circle[10] Great question—let’s break this down clearly to resolve your confusion!
First, let’s confirm your core understanding, which aligns perfectly with the simplified model the question uses:
- The
myCircleListreference variable lives on the stack and takes up 8 bytes (as specified in the question, since 64-bit references are 8 bytes here). - The
new Circle[10]creates an array object on the heap. This array holds 10 references toCircleobjects (none of which are instantiated yet—they’re just null references). Each of these 10 references takes 8 bytes, so that’s 8 * 10 = 80 bytes total for the array’s element storage.
Adding those two together (8 + 80) gives you 88 bytes, which matches the correct answer.
Now, to address your doubt about extra bytes for array length and alignment:
In a real-world JVM implementation, array objects do include additional overhead:
- An array header (which includes metadata like the array’s type and a Mark Word for garbage collection)
- A 4-byte integer to store the array length
- Memory alignment to 8-byte boundaries (to optimize CPU access)
But this question is using a simplified teaching model that focuses only on the most visible parts of memory allocation: the stack reference and the array’s element storage. It intentionally ignores the low-level JVM overhead to keep the problem focused on understanding how array references work.
So your initial understanding is completely correct for the context of this question—you don’t need to add extra bytes for array length or alignment here.
内容的提问来源于stack exchange,提问作者Suanovile

