Re: [Gc] Weak hash tables and cycles

Ivan Maidanski ivmai at mail.ru
Tue Nov 4 00:29:30 PST 2008


Hi!

ludo at gnu.org (Ludovic CourtХs) wrote:
>
> Hi,
>
> Is it possible to implement a weak-key hash table that can deal with
> cycles using disappearing links?

GC API is at least sufficient to implement Java reference reachability model.

>
> I'm in particular concerned with the following corner case: K is a key
> in a weak-key hash table, V is its associated value, and V references K.
> This leads to the following object graph, where the dotted arrow denotes
> a disappearing link:
>
>   .---.      .---.
>   | K |<-----| V |
>   `---'      `---'
>     ^          ^
>     :          |
>     :          |
>   .--------------.
>   |   weak-key   |
>   |  hash table  |
>   `--------------'
>
> Neither K nor V can become unreachable in such a case, even if none of
> them is referenced elsewhere.

Well, if You want hash table have strong refs to V then this is the behavior you want (otherwise use weak refs to V).

>
> Thanks in advance,
> Ludovic.

Bye.


More information about the Gc mailing list