1. 程式人生 > >Map存儲容量及內存占用測試

Map存儲容量及內存占用測試

print eem 內存占用 () out end sta 垃圾 free

Integer a = 1;
long start = 0;
long end = 0;
// 先垃圾回收
System.gc();
start = Runtime.getRuntime().freeMemory();
HashMap map = new HashMap();
for (int i = 0; i < 1000000; i++) {
map.put(i, a);
}
// 快要計算的時,再清理一次
System.gc();
end = Runtime.getRuntime().freeMemory();
System.out.println("一個HashMap對象占內存:" + (end - start));

Map存儲容量及內存占用測試