Bug #1481

Memory "leak" caused by ThreadLocal converter cache

Added by Michael Kay over 9 years ago. Updated about 9 years ago.

Start date:
Due date:
% Done:


Estimated time:
Legacy ID:
Applies to branch:
Fix Committed on Branch:
Fixed in Maintenance Release:


Saxon maintains a cache of "converter" objects for converting/casting values from type A to type B: if the same conversion is performed repeatedly, this avoids complex navigation of the type hierarchy to decide what to do. The cache is an LRU cache held in ThreadLocal. Because the converter objects contain a reference to a Configuration, in the case where many Configuration objects are created they can end up not being garbage collected. The fact that the cache is LRU should avoid this in theory, but in practice it seems the number of ThreadLocal objects on the heap can greatly exceed the number of threads, leading to a large number of Configuration objects, and their associated resources such as the namePool and TypeHierarchy, being locked down in memory.

Related issues

Has duplicate Saxon - Bug #1619: Memory leak generated by ConversionRules cachingDuplicate2012-09-04

<a title="Actions" class="icon-only icon-actions js-contextmenu" href="#">Actions</a>


#1 Updated by Michael Kay over 9 years ago

  • Status changed from New to Resolved

A patch for the 9.4 branch is being committed. The effect of the patch is to replace the thread-local LRU cache for converter objects with a shared thread-safe cache held by the ConversionRules object, that is, effectively, a cache owned by the Configuration.

(The 9.5 version of this fix additionally ensures that some requests for converters that currently bypass the cache no longer do so.)

#2 Updated by Michael Kay about 9 years ago

  • Status changed from Resolved to Closed
  • % Done changed from 0 to 100
  • Fixed in version set to

Please register to edit this issue

Also available in: Atom PDF