Skip to content
Permalink
Browse files

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 <cjihrig@gmail.com>
Reviewed-By: Evan Lucas <evanlucas@me.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Michaël Zasso <mic.besace@gmail.com>
  • Loading branch information...
Vladimir Varankin authored and cjihrig committed Oct 28, 2015
1 parent d9734b7 commit a5cce79ec3f0228dd3ff4311022efeb72df21426
Showing with 11 additions and 0 deletions.
  1. +1 −0 lib/console.js
  2. +10 −0 test/parallel/test-console.js
@@ -68,6 +68,7 @@ Console.prototype.timeEnd = function(label) {
const duration = process.hrtime(time);
const ms = duration[0] * 1000 + duration[1] / 1e6;
this.log('%s: %sms', label, ms.toFixed(3));
this._times.delete(label);
};


@@ -57,6 +57,16 @@ console.timeEnd('hasOwnProperty');

global.process.stdout.write = stdout_write;

// verify that console.timeEnd() doesn't leave dead links
const timesMapSize = console._times.size;
console.time('label1');
console.time('label2');
console.time('label3');
console.timeEnd('label1');
console.timeEnd('label2');
console.timeEnd('label3');
assert.strictEqual(console._times.size, timesMapSize);

assert.equal('foo\n', strings.shift());
assert.equal('foo bar\n', strings.shift());
assert.equal('foo bar hop\n', strings.shift());

0 comments on commit a5cce79

Please sign in to comment.
You can’t perform that action at this time.