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