我收到错误。 getInstance()
是否需要导入?
public class GarbageCollector
{
public static void main(String args[])
{
Runtime runtime = Runtime.getInstance();
String s ;
System.out.println(runtime.totalMemory()); // total memory required
System.out.println(runtime.freeMemory()); // memory freed
for(int i=0;i<1000;i++)
s = new String("");
System.out.println(runtime.freeMemory()); // memory after object"s"
//creation
runtime.gc();
System.out.println(runtime.freeMemory()); // memory after method call
}
}
答案 0 :(得分:0)
Runtime
类没有getInstance()
方法。
Runtime runtime = Runtime.getInstance();
应该是
Runtime runtime = Runtime.getRuntime();