(node) warning: possible EventEmitter memory leak detected. 11 message listeners added. Use emitter.setMaxListeners() to increase limit.

166 views
Skip to first unread message

Naveen Kumar Chittipolu

unread,
Sep 4, 2016, 10:30:24 AM9/4/16
to nodejs
What is the count '11' here? am I adding 11 message listeners? or it is the default number which is shown here?

Ryan Graham

unread,
Sep 4, 2016, 5:13:48 PM9/4/16
to nodejs

The EventEmitter class logs this warning when there are more than the 10 listeners subscribed to an event. The number is configurable, with 10 as the default. You are seeing 11 because it was the eleventh listener being added that triggered the warning.

The warning is meant to warn you in case you are attaching event handlers to objects that you are no longer using. In cases like that, the event handler will be referenced by the EventEmitter instance and therefore won't get garbage collected. This would potentially be a memory leak, depending on the nature of the app.

You can safely increase the limit if you know your app just happens to use lots of concurrent event handlers, but you should also make sure you aren't leaking memory as a result. Remember that if your event handler is a closure, that will retain references to everything in the closure, which means they can't be garbage collected.

See https://nodejs.org/dist/latest-v4.x/docs/api/events.html#events_emitter_setmaxlisteners_n

~Ryan


On Sun, Sep 4, 2016, 7:30 AM Naveen Kumar Chittipolu <chitt...@gmail.com> wrote:
What is the count '11' here? am I adding 11 message listeners? or it is the default number which is shown here?

--
Job board: http://jobs.nodejs.org/
New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
---
You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+un...@googlegroups.com.
To post to this group, send email to nod...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/165e54ec-8d8a-4a66-b965-4582e07f0597%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--

~Ryan

Reply all
Reply to author
Forward
0 new messages