Tried analysing memory usage of in Java Arrays (primitive data type versus Objects) using classmexer.jar with reference to the like Java memory usage.
When I tried following code I am not able to understand the output at all (I have given output of each print statement in comments)
Integer[] intObjArray = new Integer[10];
System.out.println(MemoryUtil.memoryUsageOf(intObjArray)); // 56
System.out.println(MemoryUtil.deepMemoryUsageOf(intObjArray)); // 56
for (int j =0; j< intObjArray.length ; j++) {
intObjArray[j] = new Integer(j);
}
System.out.println(MemoryUtil.memoryUsageOf(intObjArray)); //56
System.out.println(MemoryUtil.deepMemoryUsageOf(intObjArray)); //256
int[] intArray = new int[10];
System.out.println(MemoryUtil.memoryUsageOf(intArray)); //56
System.out.println(MemoryUtil.deepMemoryUsageOf(intArray)); //56
for (int j =0; j< intArray.length ; j++) {
intArray[j] = 10;
}
System.out.println(MemoryUtil.memoryUsageOf(intArray)); //56
System.out.println(MemoryUtil.deepMemoryUsageOf(intArray)); //56