4 Replies Latest reply on Dec 7, 2011 11:44 AM by Alexander Sydorenko

    KnowledgeBase keeps links to stateful sessions after disposing

    Sergii Shyika Newbie

      Hi,

      I have a problem with utilization of disposed stateful sessions. It seems that knowledge base keeps references on stateful sessions despite of it was removed by calling dispose()  method. In result garbage collector can not release resources.

      I am using jBPM 5.1.0.Final

        • 1. Re: KnowledgeBase keeps links to stateful sessions after disposing
          Tihomir Surdilovic Master

          I can assure you that there are no known memory leaks in Drools, especially something what is as core of functionality as session management. Please debug your code some more, as the problem lies there. After debugging, if you have concrete questions/info then please post them.

          • 2. Re: KnowledgeBase keeps links to stateful sessions after disposing
            Sergii Shyika Newbie

            Hi, Tihomir,  thank you for reply. I am observing memory leak with stateless sessions too. Here is simple code below:

             

             

             

            public static void main(String... args) {

             

                    KnowledgeBase base = KnowledgeBaseFactory.newKnowledgeBase();


                    waitForKeyPress();

             

                    for (int i = 0; i < 500; i++) {

                        StatelessKnowledgeSession session = base.newStatelessKnowledgeSession();

                        session.execute(buildHeavyObject());

                    }

             

                    System.out.println("Finished");

             

                    waitForKeyPress();

                }

             

             

                private static Object buildHeavyObject() {

                    List<Date> list = new ArrayList<Date>();

                    for (int i = 0; i < 1000; i++) {

                        list.add(new Date());

                    }

                    return list;

                }

             

                private static void waitForKeyPress() {

                    try {

                        System.in.read(new byte[2]);

                    } catch (IOException e) {

                        e.printStackTrace();

                    }

                }

             

             

             

             

            Here we simply create 500 stateless sessions and insert in each "heavy" object (list of 1000 dates).

            Below is jConsole screenshot made while programm waiting for second key press:

             

            Memory.png

             

            As you can see java process consumes ~3Mb before and 22Mb after invoiking sessions.

            Below is a screenshot of my debugger, that was made  after invoiking sessions:

             

            Debug.png

             

            You can see that knowledge base keeps 500 references to ProcessRuntime objects.

            The picture is the same when we using statefull sessions and dispose them by dispose() method.

            • 3. Re: KnowledgeBase keeps links to stateful sessions after disposing
              Tihomir Surdilovic Master

              Your sample code uses stateless sessions, not stateful, so not sure where dispose applies here. Stateless sessions are fire-and-forget. So once you execute it, you should set it to null in your example, otherwise yes the reference to it will keep existing.

              • 4. Re: KnowledgeBase keeps links to stateful sessions after disposing
                Alexander Sydorenko Newbie

                It won't change anything if you set variable "session" to null because it's visibility scope is limited by for operator. And if you look at screenshot you will see that garbage collecter can't free session memory because KnoledgeBase is referencing those sessions, not Main method.