setInterval(() => {
var mem = process.memoryUsage();
console.info("Memory used: ", mem.heapUsed.toString().replace(/\B(?=(\d{3})+(?!\d))/g, " "));
}, 1000);
server.get("/", function(req, res, next) {
var test = new Array(1e7);
test = null;
res.send(200);
next();
});
The interval timer keep reporting a more or less steady memory usage, but then after I make a request to the restify-endpoint, it goes up by 80 MB (natural as I assign a 10 million element array), but then it remains there. Does this mean the large array is still in memory even after I assign null to the variable?
Memory used: 82 645 408
Memory used: 82 647 240
Memory used: 82 649 072
Memory used: 82 650 904
Memory used: 82 652 736
Memory used: 163 126 464
Memory used: 163 136 128
Memory used: 163 137 968
Memory used: 163 139 808
Memory used: 163 141 648
Memory used: 163 143 488
Memory used: 163 145 328
This is a very simplified example, the end goal is to avoid objects used in api endpoints remaining in memory when they are no longer being used.