Skip to content

Commit a5cce79

Browse files
Vladimir Varankincjihrig
Vladimir Varankin
authored andcommitted
console: delete timers that have ended
Currently, console timers that have been ended with timeEnd() are not removed. This has the potential to leak memory. This commit deletes ended timers from the containing Map. PR-URL: #3562 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Evan Lucas <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Michaël Zasso <[email protected]>
1 parent d9734b7 commit a5cce79

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

lib/console.js

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ Console.prototype.timeEnd = function(label) {
6868
const duration = process.hrtime(time);
6969
const ms = duration[0] * 1000 + duration[1] / 1e6;
7070
this.log('%s: %sms', label, ms.toFixed(3));
71+
this._times.delete(label);
7172
};
7273

7374

test/parallel/test-console.js

+10
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,16 @@ console.timeEnd('hasOwnProperty');
5757

5858
global.process.stdout.write = stdout_write;
5959

60+
// verify that console.timeEnd() doesn't leave dead links
61+
const timesMapSize = console._times.size;
62+
console.time('label1');
63+
console.time('label2');
64+
console.time('label3');
65+
console.timeEnd('label1');
66+
console.timeEnd('label2');
67+
console.timeEnd('label3');
68+
assert.strictEqual(console._times.size, timesMapSize);
69+
6070
assert.equal('foo\n', strings.shift());
6171
assert.equal('foo bar\n', strings.shift());
6272
assert.equal('foo bar hop\n', strings.shift());

0 commit comments

Comments
 (0)