Uploaded image for project: 'Drools'
  1. Drools
  2. DROOLS-35

Possible memory leak: MarshallerReaderContext held indefinitely by ReteooStatefulSession

    XMLWordPrintable

Details

    • Bug
    • Status: Resolved (View Workflow)
    • Major
    • Resolution: Done
    • 5.5.0.Final
    • 5.5.1.Final, 6.0.0.Alpha9
    • None
    • None
    • Hide

      After running some code like the code below, get a memory snapshot from the JVM. Note that it still holds a MarshallerReaderContext instance as a member of the ReteooStatefulSession instance.

      Marshall/unmarshall code
      //kBase = KnowledgeBaseFactory.newKnowledgeBase(...);
      //kBase.addKnowledgePackages(kps);
      //session = kBase.newStatefulKnowledgeSession(config, null);
      
      //Insert some facts
      
      // Marshall a session
      Marshaller marshaller = MarshallerFactory.newMarshaller(session.getKnowledgeBase());
      marshaller.marshall(bOut, session);
      bOut.close();
      
      // Restart the jvm if you like
      
      // session = new session
      
      //Unmarshall the session
      Marshaller marshaller = MarshallerFactory.newMarshaller(session.getKnowledgeBase());
      
      marshaller.unmarshall(bIn, session);
      bIn.close();
      
      Show
      After running some code like the code below, get a memory snapshot from the JVM. Note that it still holds a MarshallerReaderContext instance as a member of the ReteooStatefulSession instance. Marshall/unmarshall code //kBase = KnowledgeBaseFactory.newKnowledgeBase(...); //kBase.addKnowledgePackages(kps); //session = kBase.newStatefulKnowledgeSession(config, null ); //Insert some facts // Marshall a session Marshaller marshaller = MarshallerFactory.newMarshaller(session.getKnowledgeBase()); marshaller.marshall(bOut, session); bOut.close(); // Restart the jvm if you like // session = new session //Unmarshall the session Marshaller marshaller = MarshallerFactory.newMarshaller(session.getKnowledgeBase()); marshaller.unmarshall(bIn, session); bIn.close();
    • Medium

    Description

      It seems that the memory consumption increases after a session has been unmarshalled. That is to say: an unmarshalled session of size x uses much more memory than if I had started with an empty session and inserted x number of facts.

      Digging into a memory profile, I found that after unmarshalling, my ReteooStatefulSession instance holds on to a MarshallerReaderContext instance:

      StatefulKnowledgeSessionImpl : session
      ReteooStatefulSession : defaultEntryPoint
      NamedEntryPoint : objectStore
      SingleThreadedObjectStore : identityMap
      ObjectHashMap : table
      Entry[] : [0]
      ObjectHashMap$ObjectEntry : value
      DefaultFactHandle : lastLeftTuple
      RuleTerminalNodeLeftTuple : object
      AgendaItem : context
      PropagationContextImpl : readerContext
      MarshallerReaderContext : this

      The MarshallerReaderContext consumes a lot of memory.

      Digging into the unmarshalling code, it seems that the MarshallerReaderContext is a utility class used during unmarshalling of sessions. Intuitively, it seems wrong that a reference to this object should be held after unmarshalling is finished.

      Attachments

        Activity

          People

            mfusco@redhat.com Mario Fusco
            magnusv_jira Magnus Vojbacke (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: