日期:2014-05-20 浏览次数:20826 次
public class MemoryTest {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.gc();
long total = Runtime.getRuntime().totalMemory();
long m1 = Runtime.getRuntime().freeMemory();
System.out.println("before:" + (total - m1));
Map<Object,Object> map = new HashMap<Object,Object>();
for(int i=0; i < 100; i++){
map.put(new Object(), new Object());
}
long total1 = Runtime.getRuntime().totalMemory();
long m2 = Runtime.getRuntime().freeMemory();
System.out.println("after:" + (total1 - m2));
System.out.println(map.toString());
}
}