I've noticed persistent memory leaks in my TypeScript application (3PG), leading me to believe there's an issue with memory management.
Comparison of Applications:
- 2PG -> https://github.com/theADAMJR/2pg [no memory leaks]
- 3PG -> the specific application being discussed, which extends 2PG and includes set intervals.
Here is a sample code snippet from the class of 3PG that heavily uses intervals and might be causing the problem: https://pastebin.com/Z6K8a2vK
private schedule(uuid: string, savedGuild: GuildDocument, interval: number) {
const task = this.findTask(uuid, savedGuild.id);
if (!task.timer) return;
task.status = 'ACTIVE';
task.timeout = setInterval(
async() => await this.sendTimer(task, savedGuild), interval);
}
I'm questioning whether this piece of code could be the root cause of the issue, and if so, what practices I should avoid in JavaScript that may lead to increased memory usage. Appreciate any insights.
Update: The problem was identified as discord.js triggering the ready
event multiple times, gradually consuming more memory. Acknowledging my oversight in not providing sufficient information for a precise solution.