Skip to content

Instantly share code, notes, and snippets.

@cleverca22
Created June 24, 2014 16:54
Show Gist options
  • Save cleverca22/6587ddf2c7f8730ba3fd to your computer and use it in GitHub Desktop.
Save cleverca22/6587ddf2c7f8730ba3fd to your computer and use it in GitHub Desktop.
demo a leak in mongoose
var mongoose = require('mongoose');
var Schema = mongoose.Schema, ObjectId = Schema.ObjectId;
var secondLevel = new Schema({
count:Number
});
var topLevel = new Schema({
list:[secondLevel]
});
mongoose.connect('mongodb://localhost/leak');
var model = mongoose.model('topLevel',topLevel);
model.remove(function () {
model.create({list:[{count:1}]},function (err,row) {
console.log(row,row._events.isNew);
function loop () {
row.list = [ {count:row.list[0].count+1 } ];
row.save(function (err) {
// prints the leak count console.log(row._events.isNew.length);
if (process.memoryUsage().heapTotal < 1024*1024 * 64) loop();
else {
console.log(row._events.isNew);
console.log('^^^ contents of row._events.isNew');
mongoose.disconnect();
}
});
}
loop();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment