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));

相关文章:

  • 2021-12-09
  • 2022-01-02
  • 2022-12-23
  • 2021-08-10
  • 2021-06-21
  • 2021-12-19
  • 2022-01-10
  • 2022-12-23
猜你喜欢
  • 2021-10-20
  • 2021-08-02
  • 2022-12-23
  • 2021-10-29
  • 2022-12-23
  • 2021-08-21
相关资源
相似解决方案