-2
私は次のコードを持っている:のjava - 仮想マシンのメモリ
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);
}
}
まあ、クラスNodoPrueba
だけint
属性を持っています。
前:127991976
後:128673800
違い:681824
理論はNodoPrueba
クラスは専用メモリ上16バイトを取ると言っている場合は、次の8バイトしかし、私は次の出力を持っていますオブジェクトから4バイトのintと4バイトのパディング(オブジェクトのサイズは常に8の倍数)ですが、違いはどこから来ますか?
'freeMemory'の呼び出しは、" **近似**将来割り振られたオブジェクト*のために現在利用可能なメモリーの総量*、バイト単位で測定します。オブジェクトのサイズの決定には使用できません。 –