Problem with the CLIPSJNI java library

2010-09-20
2012-11-23
  • Fabio Strocco
    Fabio Strocco
    2010-09-20

    Hi, I'm creating a project with NetBeans and I'm using the CLIPSJNI library. I tried to execute the program in the command line, without a GUI ad on NetBeans but the following error always appear

    Invalid memory access of location 0xfff80010 eip=0x2516cb48

    Java Result: 139

    This error alway appears when I assert more than 2000/2500 facts and it doesn't appear in Debug Mode (with NetBeans and with de Clips IDE debug using (run 1)).

    How can I do?

    Thanks in advance.
    Regards.

     
  • Gary Riley
    Gary Riley
    2011-03-05

    Fixed in the CLIPSJNI 0.3 release. The java classes were set up to release the underlying C data structures when the finalize method was called for the Environment class, but that runs in a separate thread from the JNI code and so won't work. You now must explicitly deallocate the C data structures from the Java code when you no longer want to use the environment. From the comments in the example programs:

    This example creates just a single environment. If you create multiple
    environments,call the destroy method when you no longer need the
    environment. This will free the C data structures associated with the
    environment.

    clips = new Environment();
    .
    .
    .
    clips.destroy();

    Calling the clear, reset, load, loadFacts, run, eval, build, assertString, and makeInstance methods can trigger CLIPS garbage collection. If you need to retain access to a PrimitiveValue returned by a prior eval, assertString, or makeInstance call, retain it and then release it after the call is made.

    PrimitiveValue pv1 = clips.eval("(myFunction foo)");
    pv1.retain();
    PrimitiveValue pv2 = clips.eval("(myFunction bar)");
    .
    .
    .
    pv1.release();