[gclist] weak pointer and gc
Sat, 14 Apr 2001 17:36:27 -0400
I don't know about Scheme, but in Common Lisp, i believe there is very little reference to garbage collection requirements. It might even be possible to have a full Common Lisp without GC, though weak references are available in specific implementations.
The CL implementations i've used, LispM, Lucid, Allegro, CMU keep symbols forever.
CLOS keeps classes for ever, and in some cases functions get kept forever.
I would consider using weak pointers an optimization that i would not bother with initially. Write a lot of scheme programs and see what they need most. However, if they are cheap enough, as Charles Fiterman suggests, you might be glad you built it in.
Alternatively, it is sometimes possible to redesign an application when it reaches a bottleneck. For example, rather than using symbols (which are cached), use strings (which are not, but might be slower to compare, ...).
As far as your XML question goes, i've found that a leaky hash table for immutable strings works very well.
Such a table will contain the most popular strings at any given time, but the table can be quite small.
At 12:30 PM 4/14/2001, Ji-Yong D. Chung wrote:
> These question is regarding a symbol
>table and garbage collector..
> I have heard that, to implement a symbol
>table properly for a sheme interpreters,
>one has to use weak pointers.
>That way, it can be garbage collected.
> Is this important for garbage collection
> I know that most local symbols (unless they are
>quoted) in scheme-expressions are converted, within
>a Scheme interpreter, into objects that represent
>lexical addresses. Thus, unless the symbols are
>used globally, the symbols are unlikely to be needed
>when the interpreter is running.
> Does the weak-pointer table gain you much
>in reducing memory?
> It seems that such a weak-pointer symbol table
>is expensive to maintain. At the garbage
>collection time, the collector probably has zero
>out the weak pointer references. Later when
>the table is accessed, via an accessor method,
>the table entries and overflow
>chains probably need to be cleaned up.
>P.S. Some time ago, there was a discussion
>thread on using hashtables for XML. If
>XML file was read into a GC collected
>environment. Would it be advisable to use
>weak pointered hashtable here (to