Memory leak in next/image appears environment-specific and involves complex image optimization logic.
The issue reports a memory leak in next/image that manifests primarily in Docker environments, with Digital Ocean deployments also affected. The problem appears related to image optimization, as disabling optimization resolves the leak. The environment-specific nature and core image handling logic make this a complex issue to diagnose and fix.
Operating System: Platform: darwin Arch: arm64 Version: Darwin Kernel Version 22.2.0: Fri Nov 11 02:03:51 PST 2022; root:xnu-8792.61.2~4/RELEASE_ARM64_T6000 Binaries: Node: 19.0.1 npm: 9.2.0 Yarn: 1.22.19 pnpm: 7.21.0 Relevant packages: next: 13.1.1 eslint-config-next: 13.1.1 react: 18.2.0 react-dom: 18.2.0
Image optimization (next/image, next/legacy/image)
https://github.com/jaunruh/next-image-test
Set up docker image:
docker build --no-cache -t next-test .docker run -p 3000:3000 --name next-test next-testSurf the app:
localhost:3000Resource usage extension to monitor the memory usageThe apps memory usage only ever increases and never really decreases anymore. On docker I have easily managed to pass 1gb in memory usage. The app was run on digitalocean as a bare nodejs app and as a docker container locally and in digitalocean. The memory usage in digitalocean (1 CPU, 512mb memory) looks as follows, but can also be reproduced with docker:

In the provided repo there are also commented-out image tags. As soon as these are used the problem disappears.
No continuous memory increase.
All major browsers
docker run and build
[NEXT-2023](https://linear.app/vercel/issue/NEXT-2023/another-memory-leak-in
Claim this issue to let others know you're working on it. You'll earn 30 points when you complete it!