-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix for memory leak caused by referenced to deferred test functions
(it/before[Each]/after[Each]). related to #1991.
- Loading branch information
Showing
4 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
function MemoryLeak() { | ||
this.myArr = []; | ||
for (var i = 0; i < 1000000; i++) { | ||
this.myArr.push(i) | ||
} | ||
} | ||
|
||
var numOfTests = 300; | ||
for (var i = 0; i < numOfTests; i += 1) { | ||
/* | ||
* This Test suite will crash V8 due to: | ||
* 'FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - process out of memory' | ||
* if all the deferred functions references have not been cleared | ||
*/ | ||
describe('Memory Leak Suite #' + i, function () { | ||
|
||
// The <closureVar> variable will be accessed by the test below. | ||
// As long as those test's functions are | ||
// referenced in memory, the closure variable may not be garbage collected | ||
// as it is still referenced. | ||
// * In a chrome heap snapshot it will appear under "system / Context" (a scope) | ||
var closureVar; | ||
|
||
before(function () { | ||
var x = closureVar ? 1 : 2 | ||
}); | ||
|
||
after(function () { | ||
var x = closureVar[0] | ||
}); | ||
|
||
beforeEach(function () { | ||
var x = closureVar ? 1 : 2 | ||
}); | ||
|
||
afterEach(function () { | ||
var x = closureVar[0] | ||
}); | ||
|
||
it('access a variable via a closure', function () { | ||
// slow performance on older node.js versions | ||
this.timeout(1000); | ||
closureVar = new MemoryLeak(); | ||
}); | ||
|
||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters