commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jack, Paul" <pj...@sfaf.org>
Subject RE: [collections] SoftRefHashMap (was RE: Avalon excalibur collec tions migration status)
Date Thu, 18 Jul 2002 00:29:09 GMT
> yes, "protected Reference createReference( Object referent ) " is
> more problematic for backwards compatibility, but I think this 
> method can not be used in new version, "purge()"  can do nothing 
> (some new private method for cleanup), and both can be depricated, 
> I believe this will not break backwards compatibility.

Well, people who expect the purge() method to do something would
have broken code.  Also, it still doesn't address all the other problems
in SoftRefHashMap.


> Very possible I understand WeakReference wrong, but as I understand GC
> clears it, and GC runs then memory is low (possible it is not 
> true), of course reachability is weaker. If it is true, both 
> reference types are almost the same for cache.

Ah, yes, you're correct.  If the garbage collector is a "stop-the-world"
one that only runs when memory is low, then WeakReference would behave
much like SoftReference.  But, it's not necessarily the case.  The 
garbage collector can run incrementally, continuously in a background
thread, in response to memory demand, or even in different ways for
different threads, depending on the JVM implementation.  The JDK1.4
VM lets you specify whether the garbage collector is incremental or
"stop-the-world".  So, in many cases, WeakReference would behave 
differently from SoftReference.

 
> I use array to hold strong references on values, it needs 
> constant time operation to manage reachability, "put" and "get" 
> calls this method for "value":
>
> private void addStrongRef(Object object) {
> 
> if (m_strongRefs != null) {
> 
> m_strongRefs[(m_current++) % m_maxStrongRefCount] = object;
> 
> }
> 
> }
> 
> May be it is possible to find a better solution.

The above algorithm is probably useful enough, but it isn't a true
MRU algorithm.  If m_strongRefs.length is 8, and I get() the same
mapping 10 times, the m_strongRefs will only have strong references
to 1 mapping, instead of the most recently used 8.

We could use an internal SequencedHashMap to store strong references,
actually, since it only keeps the x most recent mappings.

-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