Fix memory leak
This commit is contained in:
parent
fc0396d9f6
commit
5f12a23894
1 changed files with 6 additions and 1 deletions
7
main.js
7
main.js
|
@ -28,11 +28,15 @@ bot.on('error', (e) => {
|
|||
if (bot !== undefined) bot.end(e.message);
|
||||
});
|
||||
|
||||
bot.on('end', (reason) => { // Out of memory.
|
||||
bot.on('end', (reason) => { // Memory leak.
|
||||
Object.keys(bot._events).forEach((event) => { bot.removeAllListeners(event) })
|
||||
console.log(`Bot disconnect: ${reason}\nReconnect in 6 seconds...`);
|
||||
setTimeout(() => {
|
||||
createBot();
|
||||
}, 6e3);
|
||||
setTimeout(() => {
|
||||
bot = null;
|
||||
}, 20000); // 20seconds is enough
|
||||
return;
|
||||
});
|
||||
|
||||
|
@ -46,6 +50,7 @@ bot.on('custom_profilelessChat', (message, profilelessChat, packet) => {
|
|||
|
||||
bot.on('custom_systemChat', (message, systemChat, packet) => {
|
||||
console.log(`[SystemChat] ${message}`);
|
||||
console.log(JSON.stringify(systemChat.jsonMsg.message))
|
||||
});
|
||||
|
||||
bot.on('login', () => {
|
||||
|
|
Loading…
Reference in a new issue