public class Memory {
/**
* @param args
*/
public static void main(String[] args) {
long useMemory = (Runtime.getRuntime().totalMemory() - Runtime.getRuntime()
.freeMemory()) / 1024;
System.out.println("已用内存1: "
+ useMemory + "KB");
long[] use = new long[(65536-((int)useMemory))/8 * 1024];
System.out.println("空闲内存: " + Runtime.getRuntime().freeMemory() / 1024
+ "KB");
System.out.println("已用内存2: "
+ (Runtime.getRuntime().totalMemory() - Runtime.getRuntime()
.freeMemory()) / 1024 + "KB");
System.out.println("总内存: " + Runtime.getRuntime().totalMemory()/1024 + "KB");
}
}
转载于:https://my.oschina.net/skyhacker2/blog/115127