Closed
Description
opened on Nov 27, 2015
The following code is leaking memory. I tested this using node-inspector and taking heap snapshots in chrome.
var cp = require('child_process');
setInterval(function () {
var p = cp.spawn('yes');
p.stdout.read();
p.kill();
}, 50);
The leak stops if the p.stdout.read();
line is removed.
Another test, requires weak:
var cp = require('child_process');
var weak = require('weak');
var c = 0;
function cb() {
console.log(--c);
}
setInterval(function () {
var p = cp.spawn('yes');
++c;
p.stdout.read();
p.kill();
weak(p, cb);
gc();
}, 50);
Running this with --expose-gc
will display the the number of process instances that haven't been garbaged collected. The number will always be counting up and never decrease.
If the p.stdout.read()
line is removed, there will always be only one process object waiting to be collected.
Activity