I'm using express and node, and add a middleware by myself in order to convert plain text to json object, the code is as follows:
app.use(function(req, res, next){
var tmpJson ='';
req.setEncoding('utf8');
req.on('data', function(chunk){
tmpJson += chunk;
});
req.on('end', function(){
req.json = JSON.parse(tmpJson);
next();
tmpJson = null;
});
});
Will this code caused a memory leak? As far as I know, when using req.json in callback function of end event, it will increase a count of usage for req, and that will make this req never released?
If it does cause a memory leak, is there anyway I could avoid using this?