Memory Leak on ridiculously simple repo
See original GitHub issueYou guys do an awesome job and we all appreciate it! 🎉
🐛 Bug Report
On a work project we discovered a memory leak choking our CI machines. Going down the rabbit hole, I was able to recreate the memory leak using Jest
alone.
Running many test files causes a memory leak. I created a stupid simple repo with only Jest
installed and 40 tautological test files.

I tried a number of solutions from https://github.com/facebook/jest/issues/7311 but to no avail. I couldn’t find any solutions in the other memory related issues, and this seems like the most trivial repro I could find.
Workaround 😢
We run tests with --expose-gc
flag and adding this to each test file:
afterAll(() => {
global.gc && global.gc()
})
To Reproduce
Steps to reproduce the behavior:
git clone git@github.com:javinor/jest-memory-leak.git
cd jest-memory-leak
npm i
npm t
Expected behavior
Each test file should take the same amount of memory (give or take)
Link to repl or repo (highly encouraged)
https://github.com/javinor/jest-memory-leak
Run npx envinfo --preset jest
Paste the results here:
System:
OS: macOS High Sierra 10.13.6
CPU: (4) x64 Intel(R) Core(TM) i7-5557U CPU @ 3.10GHz
Binaries:
Node: 10.15.0 - ~/.nvm/versions/node/v10.15.0/bin/node
Yarn: 1.12.3 - /usr/local/bin/yarn
npm: 6.4.1 - ~/.nvm/versions/node/v10.15.0/bin/npm
npmPackages:
jest: ^24.1.0 => 24.1.0
Issue Analytics
- State:
- Created 5 years ago
- Reactions:150
- Comments:107 (18 by maintainers)
Quick Recap
jest@23
works as expected - heap size oscillates but goes down to original - it appears like the GC is succeeding to collect all memory allocated during the testsjest@24+
includingjest@26.6.3
- heap size continues to grow over time, oscillating, but doesn’t seem to go down to the initial size - My assumption is that there’s a memory leak preventing GC for freeing up all the memory@SimenB help? 🙏
Running with
jest@23
Running with
jest@26
Similar here, jest + ts-jest, simple tests get over 1GB of memory and eventually crash.