Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Revert "events: don't delete the listeners array in removeListener()"

This reverts commit 928ea56.

Keeping the original Array instance in-place essentially causes a memory leak
on EventEmitters that use an infinite number of event names (an incrementing
counter, for example), which isn't an unreasonable thing to want to do.

Fixes #3702.
  • Loading branch information...
TooTallNate committed Jul 12, 2012
1 parent 3a6314d commit 713b9249e1e7cbc028e7e4f29ef7dd6a68e03375
Showing with 2 additions and 9 deletions.
  1. +2 −0 lib/events.js
  2. +0 −9 test/simple/test-event-emitter-remove-listeners.js
@@ -214,6 +214,8 @@ EventEmitter.prototype.removeListener = function(type, listener) {

if (position < 0) return this;
list.splice(position, 1);
if (list.length == 0)
delete this._events[type];
} else if (list === listener ||
(list.listener && list.listener === listener))
{
@@ -42,15 +42,10 @@ function listener3() {
}

var e1 = new events.EventEmitter();
var e1listeners = e1.listeners('hello');
e1.on('hello', listener1);
assert.equal(e1listeners.length, 1);
e1.removeListener('hello', listener1);
assert.deepEqual([], e1.listeners('hello'));

// identity check, listeners array should be the same
assert.equal(e1listeners, e1.listeners('hello'));

var e2 = new events.EventEmitter();
e2.on('hello', listener1);
e2.removeListener('hello', listener2);
@@ -59,12 +54,8 @@ assert.deepEqual([listener1], e2.listeners('hello'));
var e3 = new events.EventEmitter();
e3.on('hello', listener1);
e3.on('hello', listener2);
var e3listeners = e3.listeners('hello');
assert.equal(e3listeners.length, 2)
e3.removeListener('hello', listener1);
assert.equal(e3listeners.length, 1)
assert.deepEqual([listener2], e3.listeners('hello'));

assert.equal(e3listeners, e3.listeners('hello'));


0 comments on commit 713b924

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