vorpal icon indicating copy to clipboard operation
vorpal copied to clipboard

Memory leak on vorpal_ui_keypress listener

Open Genide opened this issue 8 years ago • 3 comments

Creating a Vorpal instance attaches a callback to the event "vorpal_ui_keypress".

So running code like this will give you a warning.

const Vorpal = require("Vorpal");
var vorpalInst;

for (var i = 0; i < 12; i++ ) {
    vorpalInst = new Vorpal();
}

This is the warning I get back.

(node:1776) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 vorpal_ui_keypress listeners added. Use emitter.setMaxListeners() to increase limit

Shouldn't the event listener be added when you call the show method? Also, shouldn't the old vorpal instance's event listener be removed when you call the show method for a new vorpal instance?

Genide avatar May 06 '17 00:05 Genide

I am developing a vorpal extension. I have a number of unit tests that instantiate a vorpal, run it through my extension and assert its state. At some point when I added enough tests to the suite, this error showed up for me.

gdereese avatar Mar 09 '18 13:03 gdereese

@gdereese As a workaround we have the following in an afterEach hook:

vorpal.ui.removeAllListeners();

willclarktech avatar Mar 09 '18 13:03 willclarktech

@willclarktech Yep, this worked for me too. Good lookin out 👊

gdereese avatar Mar 10 '18 02:03 gdereese