You are reading a single comment by @user75013 and its replies. Click here to read the full conversation.
  • Hi,

    I’m currently using a PUCKJS device, for which I have added a library for specific hardware support.
    The library is compiled and linked with Espruino.
    I am able to load the PUCK with this new code, and invoque some functions of this library from JavaScript code running on the Espruino WEB IDE.
    All of that works well, except that I can observe an abnormal memory consumption where all resources should be released.

    Basically, the library contains the following code in the jswrap source:

    /*JSON{
      "type" : "class",
      "class" : "MyContextClass"
    }
    */
    
    /*JSON{
        "type" : "staticmethod",
        "class" : "MYCLASS",
        "name" : "open",
        "generate" : "jswrap_myclass_open",
        "return" : ["JsVar", "A context object or null if any error"]
    }
    */
    JsVar *jswrap_myclass_open(void) {
        JsVar *context = jspNewObject(0, "MyContextClass");
        if (! context) {
            jsExceptionHere(JSET_ERROR, "myclass resource failure");
            return NULL;
        }
        return(context);
    }
    
    /*JSON{
        "type" : "method",
        "class" : "MyContextClass",
        "name" : "close",
        "generate" : "jswrap_myclass_close"
    }
    */
    void jswrap_myclass_close(JsVar *parent) {
        jsvRemoveAllChildren(parent);
        jsvUnLock(parent);
    }
    

    Then, under the WEB IDE, I repeatadly execute the following lines:

    myContext = MYCLASS.open();
    myContext.close();
    process.memory();
    

    At each iteration, the process.memory displays a decreasing value for the "free" field and an increasing value for the "usage" field.

    Is there something missing or wrong in the close function that could explain why resource is consumed ?

    Thank you for your help.

About

Avatar for user75013 @user75013 started