Java学习笔记(对象的释放) (二)
air creation");
f = true;
}
finalized++;
if(finalized >= created)
System.out.println("All " + finalized + " finalized");
}
}
[java]
public class GarbageC {
public static void main(String[] args) {
while(!Chair.f) {
new Chair();
new String("To take up space");
}
System.out.println(
"After all Chairs have been created:\n" +
"total created = " + Chair.created +
", total finalized = " + Chair.finalized);
String theMethString ="after";
if(theMethString.equals("before")) {
System.out.println("gc():");
System.gc();
System.out.println("runFinalization():");
System.runFinalization();
}
System.out.println("bye!");
if(theMethString.equals("after"))
System.runFinalizersOnExit(true);
}
}
public class GarbageC {
public static void main(String[] args) {
while(!Chair.f) {
new Chair();
new String("To take up space");
}
System.out.println(
"After all Chairs have been created:\n" +
"total created = " + Chair.created +
", total finalized = " + Chair.finalized);
String theMethString ="after";
if(theMethString.equals("before")) {
System.out.println("gc():");
System.gc();
System.out.println("runFinalization():");
System.runFinalization();
}
System.out.println("bye!");
if(theMethString.equals("after"))
System.runFinalizersOnExit(true);
}
}