Image Memory Leak in NextJS?
Hi, we're running a NextJS application on a VPS, and from the looks of it the Next Image has a memory leak of some sort? Whenever loading in images, memory increases, which is expected, but it should reduce after the
minimumCacheTTL
as far as I understand, but it seems it's infinitely caching images in memory (as well as in the file-system, but that's expected).
Memory baseline for our application starts at ~200mb, and build up to 1 GB+ overtime when hundreds of images are loaded in, memory is never released.
I am also confident it's caused by Next/Image since running it with unoptimized images has zero issues and RAM stays at the baseline forever.
I'm wondering if anybody else has run into similar issues, and if there's any known fixes for this?1 Reply
Update, some more testing has been done.
It seems the RAM is kept hostage up until it is actually needed by other processes,
For example, let's say the baseline for a project is
200mb
memory usage, and after loading in a bunch of images, you're at 800mb
, and your system hits it's peak memory usage, whenever other processes actually need this memory it seems the 800mb
slowly gets lowered back up to the baseline (if needed) to keep memory usage under ~95%. I'm not sure if this is how it's supposed to work, but that's what I can see on my end
I'd love for somebody to provide their opinions on this.