canvas: asynchronous drawImage speeds up execution but causes serious memory leaks.
// this is pmap status
0000000000400000 7644 3104 0 r---- node
0000000000b77000 8 8 0 r-x-- node
0000000000b7a000 27296 13892 0 r-x-- node
0000000002800000 4 0 0 r-x-- node
0000000002801000 46796 8980 0 r---- node
00000000055b4000 16 16 8 r---- node
00000000055b8000 124 108 92 rw--- node
00000000055d7000 180 168 168 rw--- [ anon ]
00000000075e0000 5697364 5697132 5697132 rw--- [ anon ]
00000266d94c0000 256 256 256 rw--- [ anon ]
0000033e93480000 256 8 8 rw--- [ anon ]
0000036b35cc0000 256 256 256 rw--- [ anon ]
0000039136800000 256 256 256 rw--- [ anon ]
000003f309900000 256 256 256 rw--- [ anon ]
000004103ff00000 256 256 256 rw--- [ anon ]
The memory does not automatically drop to normal levels, even though I have enabled GC and cleared all cache.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 2
- Comments: 26 (14 by maintainers)
same here, memory leaks still exist on
0.1.59I tested
0.1.58on my server, the same result. The memory did not released until my server got amaxMemoryUsagecrash@Brooooooklyn amazing!! the
0.1.60significantly alleviated memory issues.However, when I tested with a sample size of 50, I found that although the memory usage decreased significantly compared to version
From the above image, it can be seen that 2GB of memory has been reclaimed, but there is still 2GB that has not been reclaimed for a long time.
0.1.59, it still exhibits noticeable slowdowns and some memory is not released.However, when I start
expose-gc, the memory recovery is particularly noticeable.there is my
envinfo@Brooooooklyn Looks good. My initial tests seem to confirm that the leak is fixed in
0.1.60. I’ve used the same script to test and I can’t find any memory at the moment.@Brooooooklyn sorry, I didn’t understand. Even if I try to download the image locally and then use
fs.readFileSyncto read it before performing theloadImageoperation, the RSS still remains high for a long time.I had also modified Panda’s script by logging the RSS by default before logging it at intervals At the beginning, it reported 61-62MB of usage, which is normal But after that, it stayed stuck at 90MB Normally, after clearing the constant named
resthat holds all theloadImageinstances, it should have gone back down to around 65MB, or maybe 70MB if some compiled code was added to the RSS during execution However, that’s not the case The amount of RAM used by theArrayBuffergenerated byloadImageincreases proportionally and exponentially each time the script is calledBecause in my script I generate GIFs (around 5 each time) Each frame has about 10 to 20 loadImage() calls, and each GIF has between 5 and 10 frames When I run this script three times, my 8GB of RAM gets maxed out, and Ubuntu starts using swap, if the server doesn’t crash
However, the script is written in TypeScript, so the promises are properly resolved I reused Panda’s script to better illustrate the issue
But in Chrome’s inspector, when using the
--inspectflag, you can clearly see thatArrayBufferinstances keep growing and are never purged The only way to clean them up is to stop the script or wait for the server to crash Alternatively with PM2, I can set a memory usage limit so that PM2 automatically restarts the processIf I reuse the script from @rambo-panda , the fix doesn’t seem to work
@Brooooooklyn Hello, excuse me for asking, but what version of
rustcare you using for the compilation? I’ve been using a Docker container created on my home computer, and I find it unable to compile properly.npm run builderror log