Created
June 24, 2014 16:54
-
-
Save cleverca22/6587ddf2c7f8730ba3fd to your computer and use it in GitHub Desktop.
demo a leak in mongoose
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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