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
NO MEMORY LEAK
USING :
And node : v21.2.0
13 Replies
- What's your exact discord.js
npm list discord.js
and node node -v
version?
- Not a discord.js issue? Check out #other-js-ts.
- Consider reading #how-to-get-help to improve your question!
- Explain what exactly your issue is.
- Post the full error stack trace, not just the top part!
- Show your code!
- Issue solved? Press the button!I can provide any information, test, code snippet.... Feel free to ask
judging by the code you provided, the image you creating using
canvas
is still stored in memory, therefore you have a "memory leak"Yeah, but how can I remove it ?
I already tried to In order to "clear it", but it doesn't work
which canvas package are you using?
"@napi-rs/canvas": "^0.1.44",
But same error for canvacord, and sharpjs, and chartjs
*same problem, there is no error until my server run out of ram
best way to go about it is to use
context.clearRect(0, 0, canvas.width, canvas.height)
I don't know if it'll be any better over the long term, but that should basically remove the bulk of the memory referenceSo creating one single instance of canvas, and clearing it before re using it again?
Because this doesnt work...
Any ideas ?
It restart. I think its a host thing to make it automatically restart.
So if I create only one instance of canvas, and clearrect each time, the issue is still here, each image generated by canvas adds 50mb to ram
No, but I asked my host and its due to the ram being full
I can see it myself, its all on the server panel in real time
its a grid of 3x2, for 400*400 img in jpg
here it is
this is for one "generation"
this add 50mb to ram, its not a problem, but it stays in ram, like the memory usage doest go back down
Its possible,but im calling manually the gc, and I tried to let the bot at 200mb for like 15 hours, nothing changed
You guessed it, I use the flag --expose-gc and then gc()
Maybe its not exactly like the native gc, but its something similar
bc its not an external librairy, its into node
global.gc behaves the same way as it would without it, but it will early activate gc
Also, for debugging forgotten memory, you will probably need to use heap snapshots
And look for addition of data of global variables, as they never get cleaned by GC