org.ozoneDB.core.storage
Class SoftReferenceCache
java.lang.Object
org.ozoneDB.core.storage.AbstractReferenceCache
org.ozoneDB.core.storage.SoftReferenceCache
- All Implemented Interfaces:
- Cache, PropertyConfigurable
- public class SoftReferenceCache
- extends AbstractReferenceCache
Caches objects which may be garbage collected at any time by the Java virtual
machine garbage collector. Uses soft references to hold objects in memory.
Note: due to bug 4640743
found here
it is currently not possible to 'override' the garbage collector by saving
a reference to an instance from its finalize statement to prevent that
object from being garbage collected. If you do try to create extra references
to an object that was only softly reachable (as with all objects that are
only referenced from this cache) after the garbage collector has decided to
throw the object away and run its finalizer, you will experience a major
memory leak.
Unfortunately, it seems that a simple self-reference through 'this' already
causes this bug to appear. Use of a finalize method on objects that are to
be put in this cache is _very_ _bad_ _news_.
bug 4190589 is a rfe that has been 'in progress' for a couple of years (!)
now, and could also solve the finalization problem. Same goes for 4227324.
Javadocs state that a garbage collector is encouraged to first collect
the softly reachable objects that are oldest. As we have no way of finding
out if this is really implemented within the current JVM, and we also have no
way to tell the gc which objects we prefer to keep in memory, and (due to bug
4640743) we cannot override the gc-s decisions, we just have to cross our
thumbs and hope that the JVM gc implementation is a smart one. The Sun
implementation uses timestamps on soft references, directly linked with the
number of times the gc has run, and it seems smart enough.
- Version:
- $Id: SoftReferenceCache.java,v 1.2 2004/03/21 21:05:51 leomekenkamp Exp $
- Author:
- Leo Mekenkamp (mind the anti sp@m)
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
SoftReferenceCache
public SoftReferenceCache(java.util.Properties properties,
java.lang.String prefix)
SoftReferenceCache
public SoftReferenceCache()
createKeyedReference
protected AbstractReferenceCache.KeyedReference createKeyedReference(java.lang.Object key,
java.lang.Object value,
java.lang.ref.ReferenceQueue referenceQueue)
- Specified by:
createKeyedReference
in class AbstractReferenceCache
main
public static void main(java.lang.String[] args)
Copyright (C) The Ozone Database Project - www.ozone-db.org. All rights reserved.