From: David Lichteblau
Subject: GC
Date: 
Message-ID: <slrn5uk1eb.dv.david.lichteblau@berlin.berlin.snafu.de>
Perhaps it is a stupid question, but if I have to structures that contain
each other, e.g.

(setf (structure-field a) b
      (structure-field b) a)

will be next GC find and delete them after I did something like

(setf a 'something-else
      b nil)

Thanks.

From: Jens Kilian
Subject: Re: GC
Date: 
Message-ID: <5spsqr$1hr@isoit109.bbn.hp.com>
David Lichteblau (················@berlin.snafu.de) wrote:
> Perhaps it is a stupid question, but if I have to structures that contain
> each other, e.g.

> (setf (structure-field a) b
>       (structure-field b) a)

> will be next GC find and delete them after I did something like

> (setf a 'something-else
>       b nil)

Yes.  Any self-respecting garbage collector will detect circular references
and free the objects regardless (unless they are still live, of course).
This is why GC works, while pure reference counting doesn't.

To quote (from memory) one of the AI Koans from the Hacker's Dictionary:

	A student came to Moon and said, "I have found a way to make a better
	garbage collector.  We just need to store a counter in each cons,
	keeping track of all the references to it."

	Moon patiently told the student the following story:

		"A student came to Moon and said...

Greetings,

	Jens.
--
··········@acm.org                 phone:+49-7031-14-7698 (HP TELNET 778-7698)
  http://www.bawue.de/~jjk/          fax:+49-7031-14-7351
PGP:       06 04 1C 35 7B DC 1F 26 As the air to a bird, or the sea to a fish,
0x555DA8B5 BB A2 F0 66 77 75 E1 08 so is contempt to the contemptible. [Blake]
From: Jon S Anthony
Subject: Re: GC
Date: 
Message-ID: <JSA.97Aug12133612@alexandria.organon.com>
In article <······························@berlin.berlin.snafu.de> ················@berlin.snafu.de (David Lichteblau) writes:

> (setf (structure-field a) b
>       (structure-field b) a)
> 
> will be next GC find and delete them after I did something like
> 
> (setf a 'something-else
>       b nil)

Presuming no other references to a or b, then if the GC is a tracing
style collector (which is almost (absolutely?) certain to be the case)
then yes.

/Jon

-- 
Jon Anthony
OMI, Belmont, MA 02178, 617.484.3383 
"Nightmares - Ha!  The way my life's been going lately,
 Who'd notice?"  -- Londo Mollari
From: Barry Margolin
Subject: Re: GC
Date: 
Message-ID: <5sou78$skl@pasilla.bbnplanet.com>
In article <······························@berlin.berlin.snafu.de>,
David Lichteblau <················@berlin.snafu.de> wrote:
>Perhaps it is a stupid question, but if I have to structures that contain
>each other, e.g.
>
>(setf (structure-field a) b
>      (structure-field b) a)
>
>will be next GC find and delete them after I did something like
>
>(setf a 'something-else
>      b nil)

If the variables A and B are the only references to the structures, then
the next GC should get rid of them.  But if you did (setq c a) or (setq d
(list a b)) at some time between the two commands you showed, then they
won't be garbage yet.

GC is conceptually very simple: if there's no way for you to get to an
object, then it's garbage and GC should delete it.

Be careful of hidden references.  For instance, if an object is returned as
the value of an expression typed to the read-eval-print loop, it will be
assigned to the variable *, then **, and then ***.  And if you're lucky
enough to be using a Lisp Machine, the history mechanism in the Lisp
Listener saves references to every object displayed in the scrollback
history, so objects that have been typed in or displayed don't become
garbage.

-- 
Barry Margolin, ······@bbnplanet.com
BBN Corporation, Cambridge, MA
Support the anti-spam movement; see <http://www.cauce.org/>
Please don't send technical questions directly to me, post them to newsgroups.