Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!samsung!uakari.primate.wisc.edu!sdd.hp.com!hplabs!otter.hpl.hp.com!otter!sfk From: sfk@otter.hpl.hp.com (Steve Knight) Newsgroups: comp.lang.lisp Subject: Re: Weak Reference in Common Lisp Message-ID: <1350026@otter.hpl.hp.com> Date: 22 Aug 90 14:42:27 GMT References: <81084@aerospace.AERO.ORG> Organization: Hewlett-Packard Laboratories, Bristol, UK. Lines: 32 Niels Mayer asks: > Does anybody have any pointers to articles on this subject? What do weak > references buy you? How do they affect performance? Why do you want them? > How do you use them? Although Common Lisp does not provide a standard mechanism for implementing weak references, some implementations provide hash-tables in which the entries can be garbage collected when the key or value or either becomes garbage. These can be used to implement weak references. In Pop11 they are called "temporary" properties. I believe they are called "populations" in Scheme. They have a number of uses. The simplest use is attaching information to data structures without having to declare extra fields in the data structure. Temporary properties allow you to do this without making the data structures permanent. Another typical use is for sparse information, such as sparse arrays, in which considerable memory savings might be made. Sometimes they are useful to provide ways of iterating over all members of a set without making the members of the set permanent. For implementations (such as Poplog Common Lisp) in which it is possible to mark entries as garbage collectable if either key or value becomes garbage, it is convenient to represent two-way relations without nasty store implications. The cost of temporary properties is to make the garbage collection algorithm slightly more complicated & to necessitate rehashing after GC. These are typically small costs. I hope these quick comments are useful. Steve Knight