Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Delete the cloned data structure when we're done with it so that we d…

…on't leak memory.
  • Loading branch information...
commit 5e5f258a0192d17d947636a29e1dcf47e1431150 1 parent 1e07733
@creationix authored
Showing with 11 additions and 4 deletions.
  1. +11 −4 lib/conductor.js
View
15 lib/conductor.js
@@ -115,14 +115,16 @@ function Conduct(definitions) {
return function performerEngine() {
+ var localPerformers = {},
+ callback;
+
// Clone the performers structure so we don't mess with the original.
- var localPerformers = {};
performers.forEach(function (performer, name) {
var newPerformer = localPerformers[name] = {};
performer.forEach(function (value, key) {
if (key === 'pendingData') {
newPerformer.pendingData = [];
- for (var i = 0,l = value.length; i < l; i++) {
+ for (var i = 0, l = value.length; i < l; i++) {
newPerformer.pendingData[i] = value[i];
}
} else {
@@ -160,9 +162,14 @@ function Conduct(definitions) {
performer.fn.apply(null, args);
}
-
// Grab the last arguments as the callback
- globalCallback = arguments[arguments.length - 1];
+ callback = arguments[arguments.length - 1];
+ globalCallback = function () {
+ // Delete the reference to the cloned object so it can be GC'd
+ delete localPerformers;
+ // Pass-through to the real callback
+ return callback.apply(null, arguments);
+ };
// Dispatch any arguments coming into the engine
dispatch(localPerformers._.outputs, arguments);
Please sign in to comment.
Something went wrong with that request. Please try again.