Why leaking memory?

Run through pm2, the memory flows over a megabyte in five minutes.

var request = require('request');
var Telegram = require('node-telegram-bot-api');
var jsonfile = require('jsonfile');

var file = 'users.json';

var api = new Telegram('token');

var bot = {
 users: {},
 getUsers: function() {
 var self = this;
 return new Promise(function(resolve, reject) {
 jsonfile.readFile(file, function(err, obj) {
 if (err) {
reject();
 } else {
 self.users = obj;
resolve();
}
})
})
},
 check: function() {
 var self = this;
 Object.keys(self.users).forEach(function(key) {
request({
 url: 'https://www.instagram.com/'+ key +'/?__a=1',
 json: true,
 }, function (error, response, body) {
 if (!error && response.statusCode == 200 && !body.user.is_private) {
 if (body.user.media.nodes[0].display_src !== self.users[key]) {
 self.users[key] = body.user.media.nodes[0].display_src;
 jsonfile.writeFile(file, self.users);
self.send(key);
}
}
})
})
},
 send: function(key) {
request({
 url: this.users[key],
 encoding: null,
 }, function (error, response, body) {
 if (!error && response.statusCode === 200) {
 api.sendPhoto('11111111', body, {
 caption: key+' posted new photo',
});
}
})
}
}


bot.getUsers().then(setInterval(function() {
bot.check();
}, 60000))


Thank you!
July 2nd 19 at 13:50
1 answer
July 2nd 19 at 13:52
Solution
Given that the programmer has no control in JS memory usage, it is normal for the node.
In your code there is no problem, but somewhere in dependencies is a bad code that will cache whether or not zonulae demanding information, which he knows but not zonulae and creates a new object of the same type. And all the trash at the mercy of the garbage collector, which waits to be executed a certain number of memory fetches for the process.
Run node --v8-options, see and experiment with the parameters of the behavior of the garbage collector.

Find more questions by tags JavaScriptNode.js