import java.lang.Runtime; import java.lang.Process; ... class myRuntime { void method(String cmd) throws IOException, InterruptedException { Process proc; Runtime run = Runtime.getRuntime(); System.out.println("Free memory is " + run.freeMemory()); run.gc(); // garbage collector System.out.println("Free memory is " + run.freeMemory()); proc = run.exec(cmd); proc.waitFor(); System.out.println("Exit status is " + proc.exitValue()); } }