[comp.lang.lisp] EXPLAINING: Weak References

gjc@paradigm.com (08/18/90)

Somebody asks:
>>Sorry, I don't know, infact I'd like to find out more about weak
>>references.
>>How do you use them?

>> Any references?

An obscure reference: It is kind of like GCTWA in Maclisp.
(Garbage Collect Truly Worthless Atoms [really symbols]).
That is, in Maclisp a GCTWA would cause all symbols which
are ONLY REFERENCED BY THE SYMBOL TABLE (sorry, I mean OBARRAY)
and which had no function definition, value, or other properties,
(and of course was not referenced by compiled code) to be
removed from the OBARRAY. Then it could be really GC'd and put
back on the freelist.

A weak reference is one way of accomplishing this sort of thing
in a more general context.

An even more obscure reference: JONL's string-package for PDP-10 MACLISP.
Used a TYPE-NIL array to point to all the hunks which were string
headers which had been consed. If, after a GC, (hence +INTERNAL-GC-DAEMON)
any of these hunks had been GC'd (i.e. had been consed onto the freelist,
so certain slots were bashed) then the rest of the storage which the
string header pointed to could be free'd (aka malloc and free).

Other examples: A list of file objects kept by OPEN and CLOSE,
(or rather a weak list, set, or array). If any have been GC'd
(e.g. put on a freelist, or end up being on a PAGE which has been
marked oldspace-free) then the other side-effects of opening the
file can be reversed, i.e. an operating-system-level CLOSE.

More complex: keys in a hashtable (like the GCTWA thing).

I'm sure we are getting the idea now...


-gjc

p.s. who can think of more obscure references?