axiom icon indicating copy to clipboard operation
axiom copied to clipboard

JsExecuteContext memory leak

Open rpaquay opened this issue 9 years ago • 0 comments

Every time we run a command in wash (e.g. echo foo), we leak 2 instances of JsExecuteContext.

It seems the culprit is the call to dependsOn in the ExecuteContext contructor:

export var ExecuteContext = function(fileSystem, stdio, path, args) {
  Ephemeral.call(this);

  (...)
  // If the parent file system is closed, we close too.
  this.dependsOn(this.fileSystem);
  (...)
};

And the dependsOn function:

Ephemeral.prototype.dependsOn = function(otherEphemeral) {
  otherEphemeral.onClose.addListener(
    function() {
      if (this.isEphemeral('Closed', 'Error'))
        return;

      this.closeError(new AxiomError.ParentClosed(otherEphemeral.closeReason,
                                                  otherEphemeral.closeValue));
    }.bind(this));
};

What happens in this case:

  • otherEphemeral is the jsfs file system instance, which lives much longer that the execute context
  • this is the execute context, and it is captured by a closure added to otherEphemeral
  • Hence, the execute context will live as long as the file system lives.

While this is technically not a memory leak, the effect for wash is that we keep alive all instances of execute context we create, because the file system instance is never released.

rpaquay avatar May 15 '15 22:05 rpaquay