Newsgroups: alt.lang.design,comp.lang.c,comp.lang.c++,comp.lang.lisp
Path: cantaloupe.srv.cs.cmu.edu!rochester!udel!gatech!howland.reston.ans.net!pipex!uunet!psinntp!relay.lehman.com!newshost!rfb
From: rfb@lehman.com (Rick Busdiecker)
Subject: Re: Reference Counting (was Re: Searching Method for Incremental Garbage Collection)
In-Reply-To: Richard Berman's message of 24 Nov 1994 22:10:36 GMT
To: Richard Berman <sts@crl.com>
Message-ID: <RFB.94Nov25111447@cfdevx1.lehman.com>
Lines: 33
Sender: news@lehman.com (News)
Nntp-Posting-Host: cfdevx1
X-Pgp-Version: 2.6
Fcc: +posts
Organization: Lehman Brothers, Inc.
X-Pgp-Signed: iQCVAgUBLtYNb5NR+/jb2ZlNAQEr0QP8DywjJINkoaq0NkOFnH53zqHG1dral1on
	      ckBuPObfuaB8lZB1Tq5CLNWevTL32UMp3JKb9II+hPBrElpNc46DFbVVVRV5Sfln
	      EMFl8x1PgPqN1h7n18RLGv3r/A88cL52oAB+wk40oii+5A+xr1cPgnwkRHDyBloY
	      rlobyRI7mj4=
	      =ygsf
References: <CzHCvp.9rM@rheged.dircon.co.uk> <TFB.94Nov21091959@burns.cogsci.ed.ac.uk>
	<1994Nov21.181455.13457@isis.muc.de> <CzoE9n.3oM@research.att.com>
	<3atajl$6sh@gateway.wiltel.com> <3b330s$g2j@nntp.crl.com>
Date: Fri, 25 Nov 1994 16:14:47 GMT
Xref: glinda.oz.cs.cmu.edu comp.lang.c:117875 comp.lang.c++:100359 comp.lang.lisp:15802

In article <3b330s$g2j@nntp.crl.com> Richard Berman <sts@crl.com> writes:

   A reference count is incremented when a reference to the object is 
   established.  When the reference is broken, the count is decremented.
   You *don't* go down the reference chain, incrementing all indirect reference
   counters.

Correct.  This is how reference counting is normally done.

   That works fine, and is reasonably fast.  

No, it exhibits the classic problem with reference counting --
circular references are never freed:

  {
    rcObject a;	    // a's RC is now 1 via rcObject constructor.
    rcObject b;	    // b's RC is now 1 via rcObject constructor.
    a ["b"] = b;    // b's RC is now 2 via the assignment.
    b ["a"] = a;    // a's RC is now 2 via the assignment.
  }		    // rcObject's RC-decrementing destructor fires here.

At the end, a has one reference (from b) and b has one reference (from a).

RC's failure to handle circularities is well known and (usually)
undisputed.  If you use RC for garbage collection, you either have to
avoid circular data structures or you have to provide a `fall back'
mechanism that will address circularities.

--
Rick Busdiecker <rfb@lehman.com>      Please do not send electronic junk mail!
  Lehman Brothers Inc.
  3 World Financial Center  "The more laws and order are made prominent, the
  New York, NY  10285-1100   more thieves and robbers there will be." --Lao Tzu
