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

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

  • Loading branch information...
TooTallNate committed Mar 15, 2012
1 parent 761a82b commit 928ea564d16da47e615ddac627e0b4d4a40d8196
Showing with 9 additions and 2 deletions.
  1. +0 −2 lib/events.js
  2. +9 −0 test/simple/test-event-emitter-remove-listeners.js
@@ -186,8 +186,6 @@ 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,10 +42,15 @@ 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);
@@ -54,8 +59,12 @@ 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'));


1 comment on commit 928ea56

@quartzo

This comment has been minimized.

Copy link

commented on 928ea56 Jul 12, 2012

It seems that this commit creates a memory leak: mongodb-native uses a incremental reference for every request, and this._events keeps all the older references as a zero length array.

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