// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
public class SizeOf2 {
    private final static int N = 1000000;
    public static long mem() {
        System.gc();
        Runtime rt = Runtime.getRuntime();
        return rt.totalMemory() - rt.freeMemory();
    }
    public static void main(String[] args) {
        long m1 = mem();
        int[] ia = new int[N];
        long m2 = mem();
        System.out.println("sizeof int = " + (m2 - m1)*1.0/N);
        ia = null;
        long m3 = mem();
        double[] xa = new double[N];
        long m4 = mem();
        System.out.println("sizeof double = " + (m4 - m3)*1.0/N);
        xa = null;
    }
}
