I am studying Java 8 documentation for ArrayList
. I got that maximum array size is defined as Integer.MAX_VALUE - 8
means 2^31 – 8 = 2 147 483 639. Then I have focused on why 8 is subtracted or why not less than 8
or more than 8
is subtracted?
/**
* The maximum size of array to allocate.
* Some VMs reserve some header words in an array.
* Attempts to allocate larger arrays may result in
* OutOfMemoryError: Requested array size exceeds VM limit
*/
private static final int MAX_ARRAY_SIZE = Integer.MAX_VALUE - 8;
I got some related answers but not fulfilling my thrust.
- Do Java arrays have a maximum size?
- How many data a list can hold at the maximum
- Why I can't create an array with large size?
Some people given some logic that as per documentation "Some VMs reserve some header words in an array"
. So for header words, 8 is subtracted. But on that case, if header words need more than 8, then what will be the answer?
Please clarify me on that basis. Advance thanks for your cooperation.