I am finding how much memory each of the variable consumes in a sample piece of code of I am writing by referring http://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html
class A{
public static void main(String[] args){
int a; // 4 bytes
int b = 2; // 4 bytes
char c = 'a'; // 2 bytes
B d; // 8 bytes, reference to a 64bit memory takes up 8 bytes
B e = new B();// 12 bytes, 8 bytes for reference + 4 bytes for int within it
}
}
class B{
int x;
}
I am trying to understand the memory footprint of a simple java program here. Are my understanding of memory footprint correct here. Also I want to know how much does each class consume. If class B did not have any fields in it, is there is still a B.class file generated and what does it contain.