Consider the below case
int[] anArray = new int[10];
Allocates memory for 10 elements of each 32-bit on heap.Right ?
So what is the size of the element if the element type is Object. ??
like
Object[] objArray = new Object[10];
How much memory allocated now on heap ? I just got the doubt by ssing the source code of ArrayList
.
private transient Object[] elementData;
Just tried this line in my machine
List<String> s = new ArrayList<String>(Integer.MAX_VALUE);
results
Exception in thread "main" java.lang.OutOfMemoryError: Requested array size exceeds VM limit
at java.util.ArrayList.<init>(Unknown Source)
at com.nextenders.server.guice.actions.servlets.Test.main(Test.java:13)
So I'm trying to know how much memory allocated.