canvas
canvas copied to clipboard
Memory leak of `text` & app crash on `encode('png')`
Discovered memory leak while drawing text
and segmentation error app crash when encoding
I created minimum reproducible example repository here https://github.com/MarosPistej/napi-rs-canvas-text-mem-leak
I have also encountered this leak, I think the encoding crash might be a separate issue (related to how skia handles the underlying buffer, for example if you pass the buffer to another tool like sharp without copying it first, then you'll get the seg error). Also the leak can occur even when the encoding step doesn't take place.
I'm wondering if paragraph
needs to have reset()
called at the end? I'm not a pro at C++, so I'm just trying to understand the cause of the leak, but looking at how paragraph is created it appears to use make_unique, which from my understanding is a kind of smarter/safer alternative to new
. Although, reading this SO question, it is pointed out that something created via make_unique should subsequently called reset()
to free the memory. However, I noticed in the code in my first link, there's no call to reset.
I may have been slightly incorrect, but this reference says that if release()
is called, something else needs to take care of deleting the object with delete
.
/cc @doodlewind
I tried adding delete paragraph;
to the end of the function and tried building again. I didn't notice any difference in the memory with my tests, too much memory still being used and not released. In fact I believe I was also incorrect earlier about encode not also having some kind of leak, but it could possibly be my code.