Marak/node_mailer — Issue #56: Calling send() in loop with 11+ iterations causes memory leak warning
Author: clintharris
Created: 2011-12-01 15:48:00+00:00
State: open

Getting the following when I fire off emails inside a loop with 11+ iterations (i.e., 10 or fewer iterations doesn't generate this warning):

```
c$ node mailer-test.js
(node) warning: possible EventEmitter memory leak detected. 11 listeners added. Use emitter.setMaxListeners() to increase limit.
Trace:
at SMTPClient. (events.js:133:17)
at SMTPClientPool.send (/Users/c/dev/mailer-test/node_modules/mailer/lib/node_mailer.js:72:10)
at dispatchMail (/Users/c/dev/mailer-test/node_modules/mailer/lib/node_mailer.js:112:12)
at Object.node_mail [as send] (/Users/c/dev/mailer-test/node_modules/mailer/lib/node_mailer.js:159:5)
at Object. (/Users/c/dev/mailer-test/mailer-test.js:5:10)
at Module._compile (module.js:425:26)
at Object..js (module.js:443:10)
at Module.load (module.js:344:31)
at Function._load (module.js:303:12)
at Array.0 (module.js:463:10)

```

To be clear, everything works (emails are sent)--just reporting the memory leak warning. Maybe a false positive?

Tested with mailer 0.6.7 and node 0.5.7 (darwin) / 0.6.3 (win32) using the following:

```javascript
var mailer = require('mailer');

for(var i = 0; i < 11; i++) { // Change 11 to 10 and warnings no longer appear
mailer.send({
to: 'Some Body ',
from : 'Me ',
subject: 'Test '+i,
body: 'Blah',
host : "xxx",
port : "465",
ssl: true,
authentication : "login",
username : "xxx",
password : "yyy"
},
function(err, result){
if(err){ console.log(err); }
}
);
}
```