Skip to content

Child process/streams memory leak #4049

Closed
@jhenninger

Description

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    child_processIssues and PRs related to the child_process subsystem.memoryIssues and PRs related to the memory management or memory footprint.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions