Project

Profile

Help

Bug #1619

closed

Memory leak generated by ConversionRules caching

Added by Alex Jitianu over 11 years ago. Updated over 11 years ago.

Status:
Duplicate
Priority:
Low
Assignee:
Category:
Performance
Sprint/Milestone:
-
Start date:
2012-09-04
Due date:
% Done:

0%

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

Description

In net.sf.saxon.lib.ConversionRules there are 2 fields: converterCache and stringConverterCache that are stored in the thread's local variable map. These fields are not removed from the tread's map when the transformation or validation ends. So if you execute multiple transformations or validations from the same thread these objects will accumulate.

In our situation we were validating and the LRUCache kept instances of StringToNCName which kept a reference to ConversionRules which kept references to SingleNamespaceSchema (through the notationSet field). So nothing gets unallocated until the thread dies.

If you whould run a code like the one below you would notice that the used memory keeps growing:

  public static void main(String[] args) throws Exception {
    File schema = new File("samples/personal.xsd");
    printMemory();
    
    for (int i = 0; i < 50; i++) {
      System.out.println("Step " + i);
      printMemory();
      SchemaFactoryImpl schemaFactoryImpl = new SchemaFactoryImpl(new EnterpriseConfiguration());
      Schema schemaGrammar = schemaFactoryImpl.newSchema(schema);
      Validator schemaValidator = schemaGrammar.newValidator();
      Source source = new StreamSource(new File("samples/personal-schema.xml"));
      schemaValidator.validate(source);
    }
    
    printMemory();
  }
  
  /**
   * Log memory data.
   */
  public static void printMemory() {
    System.gc();
    System.runFinalization();
    System.gc();
    System.runFinalization();

    try {
      Thread.sleep(100);
    } catch (InterruptedException ex) {
      //Negglecting
    }
    
    long totalMemory = Runtime.getRuntime().totalMemory();
    System.out.println("-------------------------------------\n");
    long freeMemory = Runtime.getRuntime().freeMemory(); 
    System.out.println("Used memory " + ((totalMemory - freeMemory) / 1024) + " KB");
  }
<pre>

 

Related issues

Is duplicate of Saxon - Bug #1481: Memory "leak" caused by ThreadLocal converter cacheClosedMichael Kay2012-04-17

Actions
Actions #1

Updated by O'Neil Delpratt over 11 years ago

  • Status changed from New to Duplicate

HI Alex,

Thanks for reporting the problem you have encountered. This bug is a duplicate of the reported issue #1481, which has now been fixed in Saxon maintenance release 9.4.0.4.

Please register to edit this issue

Also available in: Atom PDF