Memory leak while using node 16 (but not 14)
Prerequisites
- [X] I confirm my issue is not in the opened issues
- [X] I confirm the Frequently Asked Questions didn't contain the answer to my issue
Environment check
- [X] I'm using the latest
mswversion - [x] I'm using Node.js version 14 or higher
Node.js version
v16.14.2
Reproduction repository
https://github.com/mathanpec/msw-memory-leak-test
Reproduction steps
- Use node version
16. - Clone the reproduction repo (originally created by @mathanpec for #710).
- Edit package.json to change
mswpackage version to0.39.2and executeyarn install. - Execute
node --expose-gc ./node_modules/.bin/jest --silent --runInBand --logHeapUsage. - Notice the heap usage increase for each test.
Current behavior
There seems to be some memory leak going on when using node 16.
The heap profile also seems to show multiple copies of the same msw index file.

Expected behavior
Memory heap should not increase for each test file run when using node 16. Executing jest with node 14 does not cause any memory leak as shown in the following screenshot:
Hey, @jyuvaraj03. Thank you for reporting this one!
We will look into the reproduction repo and investigate what is causing the leak. I somewhat doubt it's related to Node 16 but rather to the latest version of MSW. But I can't rule out any options just yet.
If anybody has time to look into this, I'd appreciate the help. Otherwise, I'd get to it when I have time.
so should we downgrade the msw version?
@finalight, if you're experiencing this issue then yes, by all means, remediate it by downgrading. I'd much appreciate help with this one, it shouldn't take too much time to analyze the profiler's output and see where the memory heap/leak occurs.
We also experience this issue, except we don't use msw. It also reproduces on Node 18.
We also experience this issue, except we don't use
msw. It also reproduces on Node 18.
ah i see, so the memory leak is because of the node, not the msw
I searched around a little. It seems the memory leak is in jest itself (for node 16.11.0+) and not in msw. @kettanaito, feel free to close this issue if needed. Here's the bug report in the jest repo if anyone is interested.