垃圾回收实例

来源:互联网 发布:网络方面 证书 编辑:程序博客网 时间:2024/06/05 08:08

package 垃圾回收;
import java.applet.*;
import java.awt.*;
class thing
{
  public static int thingcount = 0;
  public static int thingfinal = 0;
  public thing()
  {
    ++thingcount;
  }
  protected void finalize()
  {
    ++thingfinal;
  }
}
public class Test extends Applet
{
  public Test()
  {
  }
  public String getAppletInfo()
  {
    return "Name: final_thing/r/n" +
           "Author: Tim Gooch/r/n" +
           "Created with Microsoft " +
           "Visual J++ Version 1.1";
  }
  public void init()
  {
      resize(320, 240);
  }
  public void destroy()
  {
  }
  public void paint(Graphics g)
  {
    g.drawString("Created with Microsoft" +
      "Visual J++ Version 1.1", 10, 20);
  }
  public void start()
  {
    while(thing.thingfinal < 1)
    {
      new thing();
    }
  }
  public void stop()
  {
    // System.gc();
    System.out.println(thing.thingcount +
      " things constructed");
    System.out.println(thing.thingfinal +
      " things finalized");
  }
}

0 0
原创粉丝点击