I have some unexpected results in my Nodetime heap snapshot:

Am I reading this right, that in my heap are 1706 instances of "user"? It seems absurdly tall, I'm not even sure how I would single it out a lot. Anyway, are there any tips / hints / tips to find out why they hang around? I have already used JSHint for my code to ensure that no free global blocks will be allocated. Everything should be wrapped up in the request closing volume ... so why users, messages, etc. Do not collect garbage when the request ends? Here is some (edited) code to show how I do things ...
What is surprising is that I took a snapshot with a bunch of about 10 m after the last API call . Thus, these objects hung around all the time after the queries that caused their selection were completed!
the code:
var User = require('./user').User, Q = require('q'); // this function is called via express' router, eg when the client visits myapi.com/users/zane function getUser(req, res, next) { var user = extend({},User).initialize(); Q.ncall(user.model.find, user.model, {'username': req.arguments[0]}) .then(function(data){ res.writeHead(200, {}); res.end(JSON.stringify(data)); }) .fail(next).end(); }
And the User module looks something like this:
exports.User = extend({}, { initialize: function() { var Schema = api.mongoose.Schema; this.schema = new Schema({ 'username': {'type':String, 'index':true} }); this.model = api.db.model('users', this.schema); }
Based on my express code above, I expect that the lifetime of the user object will only be allocated until the request is returned. Is there any key idea of ββNode.js GC here?
Zane Claes Oct. 14 '12 at 14:56 2012-10-14 14:56
source share