mocha: Error object stored on Runnable._trace leaks memory

FYI: In V8, Error objects keep closures alive until the err.stack property is accessed, which prevents collection of the closure (and associated objects) until the Error objects die.

Mocha creates a long-living Error for each Runnable: https://github.com/mochajs/mocha/blob/2303c669ef1b47fef7cf86f5ef486d537033d443/lib/runnable.js#L56.

Would it make sense to either 1. store a string message instead of an Error, or 2. clear Error.stack, or 3. format Error.stack eagerly instead?

See also: https://crbug.com/v8/7142 and https://twitter.com/wSokra/status/935790750188625920.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 17 (10 by maintainers)

Commits related to this issue

Most upvoted comments

@HarrySarson Not a bad idea, but it’s also kind of an obscure thing to add a command-line flag for. AFAIK this also affects browser (Chrome) users.

I think I’d like to just rip it out for now and see how it goes.