1 PackageCn.skyfffire;2 3 /**4 * 5 * @authorSkyfffire6 *7 */8 Public classTest {9 Static BooleanGcrun =false;//GC is the garbage collectorTen Static Booleanf =false;//terminate the condition of creating an object One Static intcreated = 0;//number of objects counter A Static intfinalized = 0;//Object Destruction - inti; - the Test () { -i = + +created; - - if(created = = 47) { +System.out.println ("has reached 47"); - } + } A at protected voidFinalize () { - if(!Gcrun) { -Gcrun =true; - -SYSTEM.OUT.PRINTLN (created + "Number object creation complete"); - } in - if(I >= 47) { toSystem.out.println ("More than 47"); + -f =true; the } * $finalized++;Panax Notoginseng - if(Finalized >=created) { theSystem.out.println ("All objects Destroyed"); + } A } the } + - classGarbage { $ Public Static voidMain (string[] args) { $ if(Args.length = = 0) { -SYSTEM.ERR.PRINTLN ("Please add parameters"); - the return; - }Wuyi the while(!test.f) { - NewTest (); Wu } - AboutSystem.out.println (test.created + "---" +test.finalized); $ - if(Args[0].equals ("before")) { -SYSTEM.OUT.PRINTLN ("GC"); - System.GC (); ASystem.out.println ("Runfinalization ():"); + system.runfinalization (); the } - // $ //if (args[0].equals ("after")) { the ////System.runfinalizersonexit (false); the // } the } the}
Java Memory Release--"Thinking in Java" essay 004