Skip to content

Commit 1e137c2

Browse files
falsandtruRafaelGSS
authored andcommitted
lib: fix reference leak
PR-URL: #44499 Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Zeyu "Alex" Yang <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Minwoo Jung <[email protected]>
1 parent f07d095 commit 1e137c2

File tree

3 files changed

+68
-0
lines changed

3 files changed

+68
-0
lines changed
+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
'use strict';
2+
const common = require('../common.js');
3+
const bench = common.createBenchmark(main, {
4+
n: [1e4, 2e4, 4e4],
5+
loop: [1e2, 2e2],
6+
});
7+
8+
function main({ n, loop }) {
9+
bench.start();
10+
run();
11+
function run() {
12+
let j = 0;
13+
14+
function cb() {
15+
j++;
16+
if (j === n) {
17+
loop--;
18+
if (loop === 0) {
19+
bench.end(n);
20+
} else {
21+
run();
22+
}
23+
}
24+
}
25+
26+
for (let i = 0; i < n; i++) {
27+
if (i % 4 === 0)
28+
process.nextTick(cb, i, true, 10, 'test');
29+
else if (i % 3 === 0)
30+
process.nextTick(cb, i, true, 10);
31+
else if (i % 2 === 0)
32+
process.nextTick(cb, i, 20);
33+
else
34+
process.nextTick(cb, i);
35+
}
36+
}
37+
}

benchmark/process/next-tick-loop.js

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
'use strict';
2+
const common = require('../common.js');
3+
const bench = common.createBenchmark(main, {
4+
n: [1e4, 2e4, 4e4],
5+
loop: [1e2, 2e2],
6+
});
7+
8+
function main({ n, loop }) {
9+
bench.start();
10+
run();
11+
function run() {
12+
let j = 0;
13+
14+
function cb() {
15+
j++;
16+
if (j === n) {
17+
loop--;
18+
if (loop === 0) {
19+
bench.end(n);
20+
} else {
21+
run();
22+
}
23+
}
24+
}
25+
26+
for (let i = 0; i < n; i++) {
27+
process.nextTick(cb);
28+
}
29+
}
30+
}

lib/internal/fixed_queue.js

+1
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ module.exports = class FixedQueue {
111111
if (tail.isEmpty() && tail.next !== null) {
112112
// If there is another queue, it forms the new tail.
113113
this.tail = tail.next;
114+
tail.next = null;
114115
}
115116
return next;
116117
}

0 commit comments

Comments
 (0)