java 某段代码或变量占用内存大小

xiaoxiao2021-02-28  97

long start = 0; long end = 0; // 先垃圾回收 System.gc(); start = Runtime.getRuntime().freeMemory(); Map<String, Object> res = classname.getName(); System.gc(); end = Runtime.getRuntime().freeMemory(); System.out.println("对象内存:" + (start - end)/1000.0 + " KB");

代码示例如上。

转载请注明原文地址: https://www.6miu.com/read-74686.html

最新回复(0)