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");
代码示例如上。