在每一个java应用程序中,都有唯一一个RunTime对象,该唯一的RunTime对象可通过getRunTime()方法获得。
应用程序不能创建自己的RunTime队象,
package e5_7;
public class RunTimeDemo {
public static void main(String[] args) {
Runtime r = Runtime.getRuntime();
long mem;
mem = r.totalMemory();
System.out.println("totalMemory: "+mem);
r.gc();
mem = r.freeMemory();
System.out.println("freeMemory: "+mem);
Process p = null;
try{
p = r.exec("notepad");
mem = r.freeMemory();
System.out.println("freeMemary: "+mem);
p.destroy();
}catch(Exception e){
System.out.println("发生错误!");
}
}
}