I'm using nodetime to analyze my node app. Clearly, there's a memory leak; here's my heap over a 2 day period (the 2 dropoffs are due to restarting the app):
So I'm taking heap snapshots, but having a really hard time figuring out what the cause of the leak is. The objects seem to come and go (eg, it is not always the same objects in the heap). Here's an example:
I'm not quite sure where to go from here. In this particular case, I recognize the strings represented in the "largest instances." The 2nd and 3rd strings are both coming from me loading the /me/home endpoint of the Facebook Graph using Node-OAuth.
Truth be told, I'm not actually clear if the "body" property is actually leaking, or if it was just coincidentally in the heap at the time I took the snapshot (if I take another snapshot, it is not always present).
In any case, here's an excerpt from my OAuthNetwork class:
OAuthNetwork.prototype.oauth = function() {
return new OAuth(
this.settings['url_request_token'],
this.settings['url_access_token'],
this.data['key'],
this.data['secret'],
this.settings['version'],
this.settings['url_callback'],
this.settings['encoding'],
null,//nonceSize
this.settings['request_headers']
);
};
OAuthNetwork.prototype.requestWithCredentials = function(credentials, endpoint, method, params, callback)
{
var url = this.getRequestURL(endpoint, method, params),
m = (method || 'GET').toUpperCase(),
body = (m==='PUT'||m==='POST') ? this.buildRequestBody(params) : '',
ct = this.settings.request_headers['Content-Type'] || null,
extra = null;
this.oauth()._performSecureRequest(credentials.key, credentials.secret, method, url, extra, body, ct, function(error, data, response) {
if(error)
{
callback(new Errors.External({'message':'there was an error with the remote service: '+JSON.stringify(error),'error':error,'endpoint': endpoint}));
return;
}
callback(null, {'body': data, 'response': response});
});
};
So, I'm left with the impression that the "body" field is being retained/leaked somehow. I find it peculiar that the heap snapshot specifically references the body property, though, and not the "response" property.
Can anybody provide me with some solid direction on how to go about figuring out the ultimate cause of the leak?