Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!usc!samsung!xylogics!merk!alliant!linus!think!barmar From: barmar@think.com (Barry Margolin) Newsgroups: comp.lang.lisp Subject: Re: Weak Reference in Common Lisp Message-ID: <41670@think.Think.COM> Date: 18 Aug 90 05:53:51 GMT References: <81084@aerospace.AERO.ORG> Sender: news@Think.COM Distribution: usa Organization: Thinking Machines Corporation, Cambridge MA, USA Lines: 27 In article <81084@aerospace.AERO.ORG> srt@aero.org (Scott "TCB" Turner) writes: >Is there a mechanism in Common Lisp (specifically AKCL) for weak >reference? By weak reference I mean a reference that won't prevent >garbage collection if no other references exist. No, there is no such thing in Common Lisp. Some Common Lisp implementations (Symbolics Genera 8.0 and Lucid, I believe) have an extension to hash tables that implements weak references to the keys. If the only reference to an object is as the key in such a hash table it may be removed from the hash table (along with the value) and may then be GCed. The implication is that MAPHASH won't necessarily see all the associations that were installed into a weak hash table. I haven't heard of any other types of weak references being implemented. I think they're only feasible in cells that are allowed to reference nothing. Hash table entries meet this requirement because entries may be removed; symbol value cells and CLOS slots can be "unbound", so weak references are possible there. But it wouldn't make sense to have a weak reference from a cons cell -- what does CAR return if the object had been GCed (I suppose you could wimp out and say that cells that aren't allowed to be unbound must be set to NIL)? -- Barry Margolin, Thinking Machines Corp. barmar@think.com {uunet,harvard}!think!barmar