axkibe/node-green-light — Issue #1: Memory leak
Author: scriby
Created: 2011-12-09 19:25:07+00:00
State: open

I noticed this issue when working with asyncblock. The same leak is in greenlight as well:

```javascript
var greenlight = require('greenlight');
for(var i = 0; i < 3000000; i++){
greenlight(function(green, red){

});
}
```

Watch your memory usage skyrocket. This will build up pretty slowly over time in normal instances. We were doing some testing with millions of db insertions and noticed the problem (using asyncblock).

It's a simple change to work around the problem:

```javascript
// the fiber
var fiber = Fiber(function() {
try {
fn(flow);

//Prevent memory leak
fn = null;
fiber = null;
} catch(e) {
// throw in next tick so the context matches again if yielded.
process.nextTick(function() {
throw e;
});
}
});
```

I'm not really sure why those variables need to be explicitly nulled out, though...