It's my first time creating a Nodejs server, I have noticed that global variable values are persistent between different queries to the server, that made me think should I clear arrays or do any thing else for reducing memory usage?
For example if I have an array(declared inside a function) that get pushed with values and get logged to response.send(JSON.stringify(array)), should I set it to null after the function call?
Furthermore is there a better way to handle the end of connection/request/response in Nodejs to reduce memory usage?
...
code
...
if (results.length > 0) {
var cur_data = {};
cur_data["day"] = day_i;
cur_data["data"] = results;
ret_val.push(cur_data);
}
...
code
...
finish(con, req, res, JSONstringfy(ret_val), false);
ret_val = null;
function finish(con, req, res, log, is_error)
{
req.pause();
res.status(is_error == true ? 400 : 200);
res.send(log);
con.end();
}