wifi.ping() memory leak and undefined

Posted on
  • Hello.
    I use wifi.ping wifi.ping with setInterval under v1.96 and NodeMCU, it have memory leak in case if I use callback function and function wifi.ping always return undefined. See code and result below.
    How it's may be solve? I need to have result of ping: successful or fail, without check of callback argument, in this case memory leak will not present.

    var wifi = require("Wifi");
    wifi.stopAP();
    function onInit() {
      wifi.connect("ssid", {password: "password"});
      setInterval(function(){
        console.log(wifi.ping("192.168.2.1", function(b){
          //console.log(b);
        }));
        console.log(process.memory().free);
      }, 5000);
    }
    

    result:

    undefined
    1371
    undefined
    1303
    undefined
    1218
    undefined
    1134
    undefined
    1061
    undefined
    976
    undefined
    891
    undefined
    806
    undefined
    721
    undefined
    636
    undefined
    551
    undefined
    466
    undefined
    381
    undefined
    296
    undefined
    211
    undefined
    126
    undefined
    41
    Execution Interrupted
    New interpreter error:
    Execution Interrupted
    
  • The "undefined" looks normal, as you're printing to the console the result of wifi.ping() which doesn't return anything.

    The memory hemorrhage, though... 85 jsvars per iteration!

  • Ok, I just made a change which will hopefully fix it (looks like the ping responses were causing leaks) - so hopefully cutting edge builds will have this fixed.

  • @Gordon, thanks for checking and fixing it !

  • can confirm that fix is working as expected

    test snippet:

    var Wifi = require("Wifi");
    var i = 1;
    var sleep = 7000;
    setInterval(function(){
      console.log("run:",i++);
      Wifi.ping("192.168.194.1", function(rc){
        console.log("ping result",rc);
      });
      console.log("process.memory().free",procĀ­ess.memory().free);
    },sleep);
    
    

    output:

    run: 1
    process.memory().free 1524
    ping result { "totalCount": 0, "totalBytes": 0, "totalTime": 0, "respTime": 20,
      "seqNo": 341, "timeoutCount": 0, "bytes": 32, "error": 0 }
    ping result { "totalCount": 0, "totalBytes": 0, "totalTime": 0, "respTime": 0,
      "seqNo": 0, "timeoutCount": 0, "bytes": 0, "error": -1 }
    ping result { "totalCount": 0, "totalBytes": 0, "totalTime": 0, "respTime": 11,
      "seqNo": 343, "timeoutCount": 0, "bytes": 32, "error": 0 }
    ping result { "totalCount": 0, "totalBytes": 0, "totalTime": 0, "respTime": 3,
      "seqNo": 344, "timeoutCount": 0, "bytes": 32, "error": 0 }
    ping result { "totalCount": 0, "totalBytes": 0, "totalTime": 0, "respTime": 0,
      "seqNo": 0, "timeoutCount": 0, "bytes": 0, "error": -1 }
    run: 2
    process.memory().free 1524
    ping result { "totalCount": 0, "totalBytes": 0, "totalTime": 0, "respTime": 0,
      "seqNo": 0, "timeoutCount": 0, "bytes": 0, "error": -1 }
    ping result { "totalCount": 0, "totalBytes": 0, "totalTime": 0, "respTime": 0,
      "seqNo": 0, "timeoutCount": 0, "bytes": 0, "error": -1 }
    ping result { "totalCount": 0, "totalBytes": 0, "totalTime": 0, "respTime": 27,
      "seqNo": 348, "timeoutCount": 0, "bytes": 32, "error": 0 }
    ping result { "totalCount": 0, "totalBytes": 0, "totalTime": 0, "respTime": 1,
      "seqNo": 349, "timeoutCount": 0, "bytes": 32, "error": 0 }
    ping result { "totalCount": 0, "totalBytes": 0, "totalTime": 0, "respTime": 1,
      "seqNo": 350, "timeoutCount": 0, "bytes": 32, "error": 0 }
    run: 3
    process.memory().free 1524
    ping result { "totalCount": 0, "totalBytes": 0, "totalTime": 0, "respTime": 6,
      "seqNo": 351, "timeoutCount": 0, "bytes": 32, "error": 0 }
    ping result { "totalCount": 0, "totalBytes": 0, "totalTime": 0, "respTime": 1,
      "seqNo": 352, "timeoutCount": 0, "bytes": 32, "error": 0 }
    ping result { "totalCount": 0, "totalBytes": 0, "totalTime": 0, "respTime": 1,
      "seqNo": 353, "timeoutCount": 0, "bytes": 32, "error": 0 }
    ping result { "totalCount": 0, "totalBytes": 0, "totalTime": 0, "respTime": 4,
      "seqNo": 354, "timeoutCount": 0, "bytes": 32, "error": 0 }
    ping result { "totalCount": 0, "totalBytes": 0, "totalTime": 0, "respTime": 2,
      "seqNo": 355, "timeoutCount": 0, "bytes": 32, "error": 0 }
    run: 4
    process.memory().free 1524
    ping result { "totalCount": 0, "totalBytes": 0, "totalTime": 0, "respTime": 5,
      "seqNo": 356, "timeoutCount": 0, "bytes": 32, "error": 0 }
    ping result { "totalCount": 0, "totalBytes": 0, "totalTime": 0, "respTime": 2,
      "seqNo": 357, "timeoutCount": 0, "bytes": 32, "error": 0 }
    ping result { "totalCount": 0, "totalBytes": 0, "totalTime": 0, "respTime": 2,
      "seqNo": 358, "timeoutCount": 0, "bytes": 32, "error": 0 }
    ping result { "totalCount": 0, "totalBytes": 0, "totalTime": 0, "respTime": 2,
      "seqNo": 359, "timeoutCount": 0, "bytes": 32, "error": 0 }
    ping result { "totalCount": 0, "totalBytes": 0, "totalTime": 0, "respTime": 1,
      "seqNo": 360, "timeoutCount": 0, "bytes": 32, "error": 0 }
    run: 5
    process.memory().free 1524
    ping result { "totalCount": 0, "totalBytes": 0, "totalTime": 0, "respTime": 9,
      "seqNo": 361, "timeoutCount": 0, "bytes": 32, "error": 0 }
    ping result { "totalCount": 0, "totalBytes": 0, "totalTime": 0, "respTime": 3,
      "seqNo": 362, "timeoutCount": 0, "bytes": 32, "error": 0 }
    ping result { "totalCount": 0, "totalBytes": 0, "totalTime": 0, "respTime": 2,
      "seqNo": 363, "timeoutCount": 0, "bytes": 32, "error": 0 }
    ping result { "totalCount": 0, "totalBytes": 0, "totalTime": 0, "respTime": 3,
      "seqNo": 364, "timeoutCount": 0, "bytes": 32, "error": 0 }
    ping result { "totalCount": 0, "totalBytes": 0, "totalTime": 0, "respTime": 2,
      "seqNo": 365, "timeoutCount": 0, "bytes": 32, "error": 0 }
    
    
  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

wifi.ping() memory leak and undefined

Posted by Avatar for user92517 @user92517

Actions