7te3ep
7te3ep
DIAdiscord.js - Imagine a boo! 👻
Created by 7te3ep on 1/20/2024 in #djs-questions
Attachment Memory Leak
Hi, I m experiencing a memory leak. Here is the command answer, this cause a memory leak of 5mb. In the second snippet there is no more issue, so I think its the node canvas librairy. Any idea of what Im doing wrong ? I already tried : - using canvacord - using sharpjs - sending outside of embed (without setImage) - all types of files Same problem eveytime MEMORY LEAK
callback: async (client, interaction) => {
await interaction.deferReply();

const canvas = Canvas.createCanvas(736, 882);
const context = canvas.getContext("2d");
const img = await Canvas.loadImage(`src/assets/cards/${cardId}.jpg`);
context.drawImage(img, 0, 0);

const attachment = new AttachmentBuilder(await canvas.encode("png"), {
name: "profile-image.png",
});
const embed = new EmbedBuilder().setImage(
"attachment://profile-image.png"
);

await interaction.editReply({
embeds: [embed],
files: [attachment],
ephemeral: false,
});
},
callback: async (client, interaction) => {
await interaction.deferReply();

const canvas = Canvas.createCanvas(736, 882);
const context = canvas.getContext("2d");
const img = await Canvas.loadImage(`src/assets/cards/${cardId}.jpg`);
context.drawImage(img, 0, 0);

const attachment = new AttachmentBuilder(await canvas.encode("png"), {
name: "profile-image.png",
});
const embed = new EmbedBuilder().setImage(
"attachment://profile-image.png"
);

await interaction.editReply({
embeds: [embed],
files: [attachment],
ephemeral: false,
});
},
NO MEMORY LEAK
callback: async (client, interaction) => {
await interaction.deferReply();
const attachment = new AttachmentBuilder(
`src/assets/cards/${cardId}.jpg`,
{
name: "profile-image.png",
}
);
const embed = new EmbedBuilder().setImage(
"attachment://profile-image.png"
);

await interaction.editReply({
embeds: [embed],
files: [attachment],
ephemeral: false,
});
},
callback: async (client, interaction) => {
await interaction.deferReply();
const attachment = new AttachmentBuilder(
`src/assets/cards/${cardId}.jpg`,
{
name: "profile-image.png",
}
);
const embed = new EmbedBuilder().setImage(
"attachment://profile-image.png"
);

await interaction.editReply({
embeds: [embed],
files: [attachment],
ephemeral: false,
});
},
USING :
"@napi-rs/canvas": "^0.1.44",
"discord.js": "^14.14.1",
"@napi-rs/canvas": "^0.1.44",
"discord.js": "^14.14.1",
And node : v21.2.0
32 replies