Evil nodejs memory leak - nodejs 8.9.0

76 views
Skip to first unread message

Simon H

unread,
Nov 9, 2017, 6:07:56 PM11/9/17
to nodejs
Hi all, 
I've found a fairly bad memory leak updating to nodejs 8.9.0, which I think should be of concern generally in NR.

Environment:
Nodejs 8.9.0
NR 0.17.5

Note: this did not occur in nodejs 6.11

In a function node, I have the following code:

////////////////////////////////

var starttime = new Date();

 

var AfterResize = function(err, img){

    var resizetime = (new Date()) - starttime;

    node.send([null, {payload:resizetime, topic:"resizetime"}]);

    msg.img = img;

    node.send([msg, null]);

};

 

 

var Async = false;

 

if (Async){

    // note - generates a new image

    msg.camera.resize(flow.get('width'), flow.get('height'), AfterResize);

} else {

    node.send(msg);

}

return;

////////////////////////////////////////


msg.camera is a large object.

But in the above code, we're not actually doing anything....

We get a new date, and send the msg on. (and the wire is not connected anywhere....).


What seems to happen is that nodejs 8.9.0 stores away a reference to msg so that it COULD be used when the function is called, and never releases it (at least for the 20s my pi lasts before it blows at 800mbytes memory use).

The problem also occurs if Async is set to true; but I didn't want to complicate matters with questions like 'what does resize do'!.


If the msg is NOT sent on (i.e. comment our node.send(msg) ) - the memory does not leak.

If "return msg;" is used instead, it does still leak.

If I remove the reference to msg from the function, it does not leak.


I believe this is a fairly big problem for node-red; I only found it because of the size of the video frames in my messages, but anyone using something like the above (using msg in a local function) will suffer memory leaks...


thoughts?

s

Reply all
Reply to author
Forward
0 new messages