I have upgraded to 7.0p2 and am still seeing the creeping memory.

I have tried the following...

1. Added the following statement to my .clp file:
    (set-node-index-hash 1)
2. Changed the jess.TokenTree#clear() method to allow for debugging:
    final void clear() {
        for (int i=0; i< m_hash; i++)
            if (m_tokens[i] != null)
                m_tokens[i].clear();
        m_size = 0;

        int filledCnt = 0;
        for (int i=0; i< m_tokens.length; i++)
            if (m_tokens[i] != null)
                filledCnt++;
        if (filledCnt > 0)
        {
            System.out.println(
                "filledCnt="+filledCnt+
                "; m_tokens.length="+m_tokens.length+
                "; instance="+this.hashCode());
        }
    }

When I run my Rete execution in a loop I see the m_tokens array is
steadily increasing and the number of non-null values increasing.

The only way to prevent this is to change the Jess source code as you
suggest below.  When I put in the call to Arrays.fill() then the memory
stops growing.

I am very hesitant to change the Jess source code as we use several
different usage patterns, some are transaction-oriented, some are more
knowledge-based.

I guess I don't understand the value of retaining the older tokens.
Some questions I still have:

* What is the value of the retained tokens?  
* Isn't the algorithm for releasing the tokens somewhat arbitrary?
* How can I test for the upper limit on the array size you mention?
* Why does my setting for set-node-index-hash-value have little or no
effect?

I am just trying to understand the behavior better and avoid
modifications to the source code if at all possible.  If you can guide
me on a way to keep the memory down within the current Jess source code
I would be grateful.

Matt

-----Original Message-----
From: Ernest Friedman-Hill [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, January 08, 2008 3:21 PM
To: Matt Accola
Subject: Re: JESS: TokenTree memory leak?


On Jan 8, 2008, at 4:06 PM, Matt Accola wrote:

> We should have upgraded the library long ago, it has just fallen  
> lower on priorities.  I am trying that now but need to do a  
> regression.
>
> We are calling the Rete engine repetitively in our application and  
> at the end of each evaluation we call the reset() method to return  
> the engine to empty state, ready for the next call.  Is there any  
> way to force all memory to be reclaimed and override this memory  
> retention you described?


There's no built-in way, but it would be an easy mod. In jess/ 
TokenTree.java, there's a method like

     final void clear() {
         for (int i=0; i< m_hash; i++)
             if (m_tokens[i] != null)
                 m_tokens[i].clear();
         m_size = 0;
     }


You could just change it to something like

      final void clear() {
         java.util.Arrays.fill(m_tokens, null);
         m_size = 0;
     }

Note that there's a performance tradeoff here; the next run will very  
likely turn around and re-allocate many of these same objects. Jess  
is lazy-initializing the contents of that m_tokens array, one element  
at a time; when all the m_tokens arrays of all the TokenTree objects  
are non-null, that's the upper limit I mentioned. Which  of the  
possible array elements is populated on any one run is going to  
depend entirely on the data for that run.





>
> Confidentiality Notice:
> **********************************************
> This E-mail and any attachments thereto, are intended only for use  
> by the addressee(s) named herein and may contain legally privileged  
> and/or confidential information. If you are not the intended  
> recipient of this E-mail, you are hereby notified any  
> dissemination, distribution or copying of this E-mail, and any  
> attachments thereto, is strictly prohibited. If you receive this E- 
> mail in error, please immediately notify me by reply E-mail or  
> telephone at (218) 723-7887 and permanently delete the original and  
> any copy of this E-mail, and any printout thereof.
>

---------------------------------------------------------
Ernest Friedman-Hill
Informatics & Decision Sciences          Phone: (925) 294-2154
Sandia National Labs                FAX:   (925) 294-2234
PO Box 969, MS 9012                 [EMAIL PROTECTED]
Livermore, CA 94550                 http://www.jessrules.com



Confidentiality Notice:
**********************************************
This E-mail and any attachments thereto, are intended only for use by the 
addressee(s) named herein and may contain legally privileged and/or 
confidential information. If you are not the intended recipient of this E-mail, 
you are hereby notified any dissemination, distribution or copying of this 
E-mail, and any attachments thereto, is strictly prohibited. If you receive 
this E-mail in error, please immediately notify me by reply E-mail or telephone 
at (218) 723-7887 and permanently delete the original and any copy of this 
E-mail, and any printout thereof. 

--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
in the BODY of a message to [EMAIL PROTECTED], NOT to the list
(use your own address!) List problems? Notify [EMAIL PROTECTED]
--------------------------------------------------------------------

Reply via email to