diff --git a/mocha.js b/mocha.js index d2a2458bbf..5979b5bb52 100644 --- a/mocha.js +++ b/mocha.js @@ -5058,18 +5058,9 @@ Runner.prototype.uncaught = function(err) { this.emit('end'); }; -/** - * Cleans up the reference to the test's deferred function. - * @see cleanSuiteReferences for details. - * @param {Test} test - */ -function cleanTestReferences(test) { - delete test.fn; -} - /** * Cleans up the references to all the deferred functions - * (before/after/beforeEach/afterEach) of a Suite. + * (before/after/beforeEach/afterEach) and tests of a Suite. * These must be deleted otherwise a memory leak can happen, * as those functions may reference variables from closures, * thus those variables can never be garbage collected as long @@ -5099,6 +5090,10 @@ function cleanSuiteReferences(suite) { if (isArray(suite._afterEach)) { cleanArrReferences(suite._afterEach); } + + for (var i = 0; i < suite.tests.length; i++) { + delete suite.tests[i].fn; + } } /** @@ -5133,7 +5128,6 @@ Runner.prototype.run = function(fn) { debug('start'); // references cleanup to avoid memory leaks - this.on('test end', cleanTestReferences); this.on('suite end', cleanSuiteReferences); // callback