🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #19857

Re: Java Garbage Collection

#19857
From: Grzegorz Sliwinski
Date: Wed, 10 Dec 1997 00:00
26 lines
1188 bytes
If there are no more other references to any of these two objects (only
circular), both of them get garbage collected.
Try this:
class Test1 {
  Test1 ref;
  protected void finalize() throws java.lang.Throwable{
    System.out.println("finalize called for: "+this+"->"+ref);
    super.finalize();
  }
}
class Test2 {
  static public void main(String[] args) {
    Test1 t1 = new Test1();
    t1.ref = new Test1();
    t1.ref.ref = t1;
    t1 = null;
    System.gc();
  }
}
Grzegorz Sliwinski

jetball@usa.net wrote in message <348CF489.EC3AAD1@usa.net>...
>My question is if I create two objects and have a circular reference to
>them both. Will these two objects ever be destroyed by the garbage
>collector?
Technical Details
Message-ID: <66kn7i$sr4@forums>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <348CF489.EC3AAD1@usa.net>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,7e35a16af36a1542
X-Google-Attributes: gidf74b3,public
From: "Grzegorz Sliwinski" <g.r.z.e.s.s@fast.com.pl>
Subject: Re: Java Garbage Collection
Date: 1997/12/10
Message-ID: <66kn7i$sr4@forums>
X-Deja-AN: 296758112
References: <348CF489.EC3AAD1@usa.net>
X-MimeOLE: Produced By Microsoft MimeOLE V4.71.1712.3
Organization: None
Newsgroups: borland.public.jbuilder.java.language