javascript - setInterval causing a memory overflow? -
for record, using node api lot of programming. anyway, when run code memory leak error, saying there 11 emitters open. if case, how prevent program opening several instances of getdata? if cannot prevent that, there crude way delete instances don't want emitted? trying run function every 50 ms. here code:
setinterval(getdata, 100); function getdata() { "use strict"; //when serialport opens: serialport.on("open", function() { serialport.on("data", function(data) { //takes current string value, turns integer, stores in ncurrentvalue rundata( parseint(data.tostring()) ); }); }); } getdata(); function rundata(value) { "use strict"; socket.emit('newdata',value); console.log(value); }
you extracting event triggers outside of getdata. far understand nodejs, event driven, should attach onopen / ondata once, , connections come on function calls.
i guess need following:
serialport.on("open", newconnection); serialport.on("data", newdatareceived); function newconnection() { // connection... } function newdatareceived(data) { // data received }
i'm guessing, serial port sends info when connection gets closed, add in likes of:
serialport.on("close", closeconnection); function closeconnection() { // close connection internally afterwards }
although last part pure guess...
in case, nodejs should fire open event when new connection made, , afterwards, fire data event when data received. if check library using serialport, there might guide on how use library
Comments
Post a Comment