Another Memory Leak in `next/image`
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 142k
- Forks
- 32.5k
- Avg merge
- 2d 14h
- Merged PRs (30d)
- 351
Description
Verify canary release
- I verified that the issue exists in the latest Next.js canary release
Provide environment information
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
Which area(s) of Next.js are affected? (leave empty if unsure)
Image optimization (next/image, next/legacy/image)
Link to the code that reproduces this issue
https://github.com/jaunruh/next-image-test
To Reproduce
Set up docker image:
docker build --no-cache -t next-test .docker run -p 3000:3000 --name next-test next-test
Surf the app:
- open browser at
localhost:3000 - scroll the home page and the project pages randomly
- use the
Resource usageextension to monitor the memory usage - see the memory only increase and never decrease
Describe the Bug
The 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.
Expected Behavior
No continuous memory increase.
Which browser are you using? (if relevant)
All major browsers
How are you deploying your application? (if relevant)
docker run and build
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked next-image-test reproduction and run the documented Docker build and container commands while monitoring memory usage. Compare navigation with the image tags enabled and commented out, then trace the next/image image-optimization path with a memory profiler. Done means identifying the continuous growth and verifying that memory no longer increases during repeated navigation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- docker, javascript, next.js
- Domain
- performance, web-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100