[Gc] Re: Weak hash tables and cycles

Hans Boehm Hans.Boehm at hp.com
Thu Nov 6 22:12:09 PST 2008


I think there's a way to do this, but it's not exactly elegant.

If you leave the disappearing link to K, but then hide the link to V from
the collector and register a finalizer for V, V's finalizer will be 
invoked ater a collection during
which V is only reachable from the table.  V's finalizer can check whether
the disappearing link to K is still there.  If it is, it simply 
reregisters itself as a finalizer for V.  If the disappearing link is
gone, it doesn't reregister itself, allowing V to be collected in the
next cycle.

I have not tried this.

There was an old patch posted to this list that allowed for call-backs
after the initial marking, that would probably have made this easier
and more efficient.  I think it's still on my list somewhere, but it
neveer quite made it in, at least not yet.

Hans

On Tue, 4 Nov 2008, Ludovic Courtès wrote:

> Ivan Maidanski <ivmai at mail.ru> writes:
>
>> Hi!
>>
>> ludo at gnu.org (Ludovic CourtХs) wrote:
>
>>> This is not necessarily the desired behavior when V is the only
>>> reference to K.
>>>
>>> Under Guile's current GC, which is "weak hash table aware", K becomes
>>> unreachable when V is the only reference to it.  To achieve this, the GC
>>> marks values of weak-key hash tables only once it has determined which
>>> keys are reachable.
>
>> Then just make V->K reference disappearing.
>
> The V->K reference is potentially created at the application level.
>
> Thanks,
> Ludo'.
>
> _______________________________________________
> Gc mailing list
> Gc at linux.hpl.hp.com
> http://www.hpl.hp.com/hosted/linux/mail-archives/gc/
>


More information about the Gc mailing list