Skip to Content.
Sympa Menu

xom-interest - Re: [XOM-interest] QName flyweights

xom-interest AT lists.ibiblio.org

Subject: XOM API for Processing XML with Java

List archive

Chronological Thread  
  • From: Wolfgang Hoschek <whoschek AT lbl.gov>
  • To: norwoods <norwoods AT gbronline.com>
  • Cc: xom-interest AT lists.ibiblio.org
  • Subject: Re: [XOM-interest] QName flyweights
  • Date: Thu, 9 Jun 2005 13:13:16 -0700



what is the garbage collection strategy? the qnames will remain in the hashmap even after all other references have disappeared.


Yep they remain in there, but only the most recently used 256 qnames since the map is bounded. One might better use 128, but in any case it does not appear to be a problem.


This is what I mean:

/**
* Bounded LinkedHashMap with least-recently-used (LRU) eviction policy.
*/
private static final class LRUHashMap extends java.util.LinkedHashMap {

private final int maxEntries;

private LRUHashMap(int maxEntries) {
super(1, 0.75f, true);
this.maxEntries = maxEntries;
}

protected boolean removeEldestEntry(Map.Entry eldest) {
return size() > maxEntries;
}

}

IMO, there's no need for weak or soft reference complications here since we're just talking a small number of entries here (256 or 128).

Wolfgang.




Archive powered by MHonArc 2.6.24.

Top of Page