The memory is not released when using Sharp in Electron (Some Linux distributions)
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 32.7k
- Forks
- 1.4k
- Avg merge
- 1d 14h
- Merged PRs (30d)
- 5
Description
Possible bug
Is this a possible bug in a feature of sharp, unrelated to installation?
- Running
npm install sharpcompletes without error. - Running
node -e "require('sharp')"completes without error.
Are you using the latest version of sharp?
- I am using the latest version of
sharpas reported bynpm view sharp dist-tags.latest.
What is the output of running npx envinfo --binaries --system --npmPackages=sharp --npmGlobalPackages=sharp?
System:
OS: Linux 6.8 Ubuntu 24.04.3 LTS 24.04.3 LTS (Noble Numbat)
CPU: (16) x64 AMD Ryzen 7 5700G with Radeon Graphics
Memory: 24.10 GB / 31.19 GB
Container: Yes
Shell: 5.2.21 - /bin/bash
Binaries:
Node: 22.13.1 - ~/.nvm/versions/node/v22.13.1/bin/node
npm: 10.9.2 - ~/.nvm/versions/node/v22.13.1/bin/npm
pnpm: 8.5.1 - /usr/bin/pnpm
npmPackages:
sharp: ^0.34.4 => 0.34.4
Does this problem relate to file caching?
- Adding
sharp.cache(false)does not fix this problem.
What are the steps to reproduce?
git clone https://github.com/ollm/electron-sharp-memory.git
cd electron-sharp-memory
npm install
npm start
Currently, when using Sharp on some Linux distributions through Electron, memory is not being released. To try to fix this, I've tested using global.gc() or moving Sharp into node:worker_threads, but neither worked.
When running the same Sharp script directly in Node, memory usage grows to about 200-500 MB and then stabilizes, but inside Electron it keeps increasing without stopping.
I've read issues #667 and #955.
It may also be related to #4351 and https://github.com/electron/electron/issues/46323
In Electron, Ubuntu 24.04.3 (Memory increases):
https://github.com/user-attachments/assets/18457f21-00d7-484a-8154-817514a34e1b
In Node, Ubuntu 24.04.3 (Memory remains stable):
node --expose-gc ./www/js/app.js
RSS: 0.06 GB, Heap Total: 0.01 GB, Heap Used: 0.01 GB, External: 0.00 GB
RSS: 0.12 GB, Heap Total: 0.01 GB, Heap Used: 0.01 GB, External: 0.00 GB
RSS: 0.17 GB, Heap Total: 0.01 GB, Heap Used: 0.01 GB, External: 0.00 GB
RSS: 0.19 GB, Heap Total: 0.01 GB, Heap Used: 0.01 GB, External: 0.00 GB
RSS: 0.19 GB, Heap Total: 0.01 GB, Heap Used: 0.01 GB, External: 0.00 GB
RSS: 0.19 GB, Heap Total: 0.01 GB, Heap Used: 0.01 GB, External: 0.00 GB
...
In Electron, Arch Linux (Memory remains stable, but not when running inside a Flatpak package):
https://github.com/user-attachments/assets/0bebd7fb-eed2-40f7-84c4-d7c68a30c05b
What is the expected behaviour?
That memory usage should be similar to running Sharp directly in Node.
Please provide a minimal, standalone code sample, without other dependencies, that demonstrates this problem
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 electron-sharp-memory sample, especially www/js/app.js, and run npm install followed by npm start. Compare its Electron memory behavior with the Node command shown in the report, including on Ubuntu and Flatpak; done means memory usage stabilizes similarly to direct Node execution.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- electron, javascript, node.js
- Domain
- desktop-dev, performance
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100