commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Juozas Baliuka" <bali...@centras.lt>
Subject Re: [collections] SoftRefHashMap (was RE: Avalon excalibur collections migration status)
Date Tue, 16 Jul 2002 06:24:57 GMT

Hi,
You are rigth about Phantom references, they are usefull  but not for maps,
Soft and Weak references do almost the same. I think it is good just to fix
"purge" in SoftRefHashMap and to implement MRU stuf (to hold strong
references on MRU values ).
I attached cache implementation, map can be implemented the same way.


> > It is possible to find a lot of patches in archyve for this
> > class, some I
> > posted myself a half  year ago.
>
> I'll go hunting for them (Btw, the mail archive seems broken).
>
> > > 1.  PhantomReference.get() always returns null.  This means
> > > that a mapwith phantom keys or phantom values is more or less
> > > useless.  (The keys or values would disappear as soon as you
> > > put them in the map!  For instance for phantom keys,
> > > map.put("key", "value") followed by map.containsKey("key")
> > > would always return false.)
> >
> > It useless if used without ReferenceQueue.
> > Documentation :
> > "Soft and weak references are automatically cleared by the
> > collector before being added to the queues with which they
> > are registered, if any. Therefore soft and weak references
> > need not be registered with a queue in order to be
> > useful, while phantom references do. An object that is
> > reachable via phantom references will remain so until
> > all such references are cleared or themselves become unreachable."
>
> Still, in the context of a Map, if you surround the keys or values
> with PhantomReferences, those keys or values disappear.  A Map whose
> keys or values aren't visible isn't much of a Map, so I don't see a
> use for PhantomKeyMap or PhantomValueMap.
>
>
> > > 2.  A map with soft keys would do the same thing as a map with soft
> > > values:  When memory is running low, the garbage collector
> > > would remove mappings from the map.  So it doesn't seem to be useful
> > > to allow people to specify both soft keys and soft values, since they
> > > do the same thing.
> >
> > It is not the same. Garbage collector would not remove
> > mapings if they are reacheble. Keys can be unreacheble and values can be
> > reacheble at the same time. SoftValueMap's are used for cache.
>
> That's a good point.  A SoftKeyMap could be useful in the case where there
> are strong references to the values somewhere outside of the Map, but no
> strong references to the keys...
>
> Now I'm thinking that ReferenceMap is useful for weak keys (in a
pre-JDK1.3
> application), weak values, soft keys, soft values...One class for four
> cases.
>
> So, maybe we should just eliminate its ability to use phantom references
> and submit it...but I still like Stephen's idea of using decorators for
> the soft and weak values.
>
> Thoughts?
>
> -Paul
>
>
> --
> To unsubscribe, e-mail:
<mailto:commons-dev-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail:
<mailto:commons-dev-help@jakarta.apache.org>
>

Mime
View raw message