Map占用內存大小評估


public class test {
private static java.util.HashMap<String, String> needQueryResProductList = new java.util.HashMap<String, String>();
public static void main(String[] args) throws Exception {

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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM