question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Memory Leak on ridiculously simple repo

See original GitHub issue

You 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.

jest-memory-leak

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:open
  • Created 5 years ago
  • Reactions:150
  • Comments:107 (18 by maintainers)

github_iconTop GitHub Comments

42reactions
javinorcommented, Nov 23, 2020

Quick Recap

  • Good - Running tests with 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 tests
  • Bad - Running tests with jest@24+ including jest@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
  • I took the screenshots after running @jaredjj3’s example repo - see this comment)

@SimenB help? 🙏

Running with jest@23

Screen Shot 2020-11-23 at 13 44 50

Running with jest@26

Screen Shot 2020-11-23 at 13 44 33
38reactions
fyodorvicommented, Mar 27, 2019

Similar here, jest + ts-jest, simple tests get over 1GB of memory and eventually crash.

Read more comments on GitHub >

github_iconTop Results From Across the Web

unused @Repository class will cause memory leak
The empty repository doesn't mean, that your object never gets fetched from the database. If you have relations between your objects, then they ......
Read more >
Hunting down memory leak – finding a bug in PHP ...
We were running on the latest PHP release (8.1.9) and there were no reported memory leaks in the php-src repository at the time...
Read more >
How to spot and fix memory leak, retain cycle and ... - YouTube
In this video, we learn about the common areas where leaks happen- closures- delegates- notification centers- disposeBag/anyCancellables in ...
Read more >
you are probably leaking ViewModel and might not know ...
Memory leak happens when for some reason an unused allocated memory cannot be released. If your application has an object that is no...
Read more >
How to get rid of memory leaks? A practical approach using ...
The standard definition of a memory leak is a scenario that occurs when objects are no longer being used by the application, but...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found