#Preventing High RAM Usage
10 messages · Page 1 of 1 (latest)
if (WelcomerData?.use_image == 1) {
number = Math.floor(Math.random() * 79);
console.log('[guildMemberAdd] Using image number:', number);
const card = fs.readFileSync(`./Welcome/${number}.png`);
// Read a random 2-4MB File saved locally for image background
welcomeImageAttachment = await new canvas.Welcome()
.setUsername(member.user.username)
.setDiscriminator(member.user.discriminator)
.setGuildName(member.guild.name)
.setAvatar(member.user.displayAvatarURL({ dynamic: false, extension: 'jpg' }))
.setMemberCount(member.guild.memberCount)
.setBackground(card)
.setColor('border', WelcomerData.color.slice(0,7) || '#8015EA')
.setColor('username-box', WelcomerData.color.slice(0,7) || '#8015EA')
.setColor('discriminator-box', WelcomerData.color.slice(0,7) || '#8015EA')
.setColor('message-box', WelcomerData.color.slice(0,7) || '#8015EA')
.setColor('title', WelcomerData.color.slice(0,7) || '#8015EA')
.setColor('avatar', WelcomerData.color.slice(0,7) || '#8015EA')
.toAttachment();
// Welcomer Image making complete
buffer.files = [{
attachment: welcomeImageAttachment.toBuffer(),
name: 'Welcome.png',
}];
console.log('[guildMemberAdd] Welcome image prepared.');
// The 2 lines below, are they useful in preventing high ram usage?
welcomeImageAttachment = null;
card = null;
<channel>.send(buffer) // buffer variable contains embed, message, and image
}
This is the code that gets executed everytime a member joins a server
It is using discord-canvas package though,
I need suggestions, like should i use garbage collector (and how), defining variables as null works or not etc
Thanks 😄
How do you know this is causing high ram usage? You should do some memory profiling if it’s an issue. However it’s likely what intents you use causing higher memory usage
Also, you should consider using fs/promises for reading files. Using the sync will block the event loop, whereas using the async version won’t
okk i will do the things u have suggested, thankss 😄
Chances are the fs/promises won’t make a difference. But I do remember some of those libs having memory leaks
Ok so I think it's not my code that's causing ram usage,
Its the members cache that's probably causing high ram usage cuz I have members intent 😅
Either way my problem is solved 😄