im currently trying to use Node to monitor a webpage for changes. But the thing is that after some page loads, the memory usage of node.exe goes up incredibly fast, about 40 - 50 Mb at a time. I've determined that the issue comes from this part of my code:
var cheerio = require('cheerio');
function getPage () {
http.get( 'some.url.com' , function (res) {
var page = '';
res.on('data', function (chunk) {
page += chunk; //commenting THIS
});
res.on('end', function (err) {
$ = cheerio.load(page); // and THIS makes the program run OK.
event.emit('pageLoaded');
});
});
}
setInterval(getPage,40000);
I'm using Cheerio module to do some DOM manipulation, which seems to have the biggest impact on the memory usage. Is there a way to clear the data used completely for every function call?? Thanks.