I have the following code:
public class Test2 {
public static void main(String[] args) {
long ta, after, before;
Runtime rt;
rt=Runtime.getRuntime();
rt.gc();
NodoPrueba q=new NodoPrueba(1);
before=rt.freeMemory();
q=null;
rt.gc();
after=rt.freeMemory();
ta=after-before;
System.out.println("Before: "+before+"\nAfter: "+after);
System.out.println("\nDifference: "+ta);
}
}
Well, the class NodoPrueba
only has an int
attribute. But i have the following output:
Before: 127991976
After: 128673800
Difference: 681824
If the theory says that NodoPrueba
class only takes 16 bytes on memory: 8 bytes from the object, 4 bytes for int and 4 bytes for padding (object's size is always a multiple of 8), where does the difference come from?