| 1 |
'use strict'; |
| 2 |
|
| 3 |
/* eslint no-unused-vars: off */ |
| 4 |
|
| 5 |
function MemoryLeak () { |
| 6 |
this.myArr = []; |
| 7 |
for (var i = 0; i < 1000000; i++) { |
| 8 |
this.myArr.push(i); |
| 9 |
} |
| 10 |
} |
| 11 |
|
| 12 |
var numOfTests = 300; |
| 13 |
for (var i = 0; i < numOfTests; i += 1) { |
| 14 |
/* |
| 15 |
* This Test suite will crash V8 due to: |
| 16 |
* 'FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - process out of memory' |
| 17 |
* if all the deferred functions references have not been cleared |
| 18 |
*/ |
| 19 |
describe('Memory Leak Suite #' + i, function () { |
| 20 |
// The <closureVar> variable will be accessed by the test below. |
| 21 |
// As long as those test's functions are |
| 22 |
// referenced in memory, the closure variable may not be garbage collected |
| 23 |
// as it is still referenced. |
| 24 |
// * In a chrome heap snapshot it will appear under "system / Context" (a scope) |
| 25 |
var closureVar; |
| 26 |
|
| 27 |
before(function () { |
| 28 |
var x = closureVar ? 1 : 2; |
| 29 |
}); |
| 30 |
|
| 31 |
after(function () { |
| 32 |
var x = closureVar[0]; |
| 33 |
}); |
| 34 |
|
| 35 |
beforeEach(function () { |
| 36 |
var x = closureVar ? 1 : 2; |
| 37 |
}); |
| 38 |
|
| 39 |
afterEach(function () { |
| 40 |
var x = closureVar[0]; |
| 41 |
}); |
| 42 |
|
| 43 |
it('access a variable via a closure', function () { |
| 44 |
// slow performance on older node.js versions |
| 45 |
this.timeout(1000); |
| 46 |
closureVar = new MemoryLeak(); |
| 47 |
}); |
| 48 |
}); |
| 49 |
} |