René's URL Explorer Experiment


Title: vi.fn "memory leak" with `isolate: false` · Issue #9492 · vitest-dev/vitest · GitHub

Open Graph Title: vi.fn "memory leak" with `isolate: false` · Issue #9492 · vitest-dev/vitest

X Title: vi.fn "memory leak" with `isolate: false` · Issue #9492 · vitest-dev/vitest

Description: Clear and concise description of the problem In our project, we have a need to use isolate: false and fileParallelism: false in vitest. We have seen that under this configuration, the number of vitest mocks being kept in memory grows as ...

Open Graph Description: Clear and concise description of the problem In our project, we have a need to use isolate: false and fileParallelism: false in vitest. We have seen that under this configuration, the number of vit...

X Description: Clear and concise description of the problem In our project, we have a need to use isolate: false and fileParallelism: false in vitest. We have seen that under this configuration, the number of vit...

Opengraph URL: https://github.com/vitest-dev/vitest/issues/9492

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"vi.fn \"memory leak\" with `isolate: false`","articleBody":"### Clear and concise description of the problem\n\nIn our project, we have a need to use `isolate: false` and `fileParallelism: false` in vitest.\n\nWe have seen that under this configuration, the number of vitest mocks being kept in memory grows as your test suite runs. This is not surprising given the shared context. \n\nWhat is surprising, is there is no clear mechanism to control this. \n\nThe result is that calling functions like `clearAllMocks` or `restoreAllMocks` get progressively slower over time ([as we simply loop over all active mocks](https://github.com/vitest-dev/vitest/blame/main/packages/spy/src/index.ts#L634)) - without ever having a way to reduce the size of the set.\n\nHere is a reproduction 👉  https://stackblitz.com/edit/vitest-dev-vitest-y6nkb7na?file=vite.config.ts,test%2Ftest01.test.ts,vitest.setup.ts,test%2Ftest05.test.ts,test%2Ftest04.test.ts&initialPath=__vitest__/\n\nI have 5 test files, that each create a large number of mocks and you can see the performance of `clearAllMocks` degrades over time - relative to the number of mocks being created.\nThis is an extreme case (with 1000's of mocks created) - but in our real-world case, we aren't mocking many functions - but having a lot of tests (5000+ tests) & even mocking a reasonable number of functions per test, get's out of control quickly.\n\nUsing `isolate: true`, does solve this problem - because the context is reset between tests. But this introduces other problems we then have to overcome.\n\n### Suggested solution\n\nI find it surprising there is no way to \"clean/kill mocks\" that are in memory.\nWe have the power to clean up other parts of shared context `unstubAllGlobals` or `unstubAllEnvs` are maybe good examples?\nI'd kind of expect some `killAllMocks` function.\n\n### Alternative\n\nI guess there is an argument that we should mock less things. Or not run with `isolate: false`.\nBut if we imagine for a second, that there is a use case for mocking a large number of functions in a shared context (we have one in our project) - there is not equal alternative.\n\nAlternatively I guess we could also say that `resetAllMocks` or `restoreAllMocks` should be keeping this list under control itself. I don't see any reason that we would want to just let this set grow forever as my tests run.\n\n### Additional context\n\nI'd be open to a suggestion on how to solve this problem with existing methods - without resorting to:\n- Changing `isolate:false` or `fileParallelism: false` \n- Mocking less things\n\n### Validations\n\n- [x] Follow our [Code of Conduct](https://github.com/vitest-dev/vitest/blob/main/CODE_OF_CONDUCT.md)\n- [x] Read the [Contributing Guidelines](https://github.com/vitest-dev/vitest/blob/main/CONTRIBUTING.md).\n- [x] Read the [docs](https://vitest.dev/guide/).\n- [x] Check that there isn't already an issue that request the same feature to avoid creating a duplicate.","author":{"url":"https://github.com/andrewbrennanfr","@type":"Person","name":"andrewbrennanfr"},"datePublished":"2026-01-20T14:41:25Z","url":"https://github.com/vitest-dev/vitest/issues/9492"}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react-reconciler,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@d5750093facf
route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:2d8572f7-bbc2-86dc-ccb8-5e44465b1f11
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idB558:2DAA79:4C9683:694DB2:6AED8444
html-safe-nonce99ec5b58c21e814632df7db8d73298a212f80c023e9a641b63a0bb6893d35c3b
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCNTU4OjJEQUE3OTo0Qzk2ODM6Njk0REIyOjZBRUQ4NDQ0IiwidmlzaXRvcl9pZCI6IjMwMTQzNzUwNzI4MTQ5NTc2MzYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmace491d725ec4e70dc08af6f95255456e77231c2a03257a7b9ebfad95f03d0b68f
hovercard-subject-tagissue:3834031589
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/vitest-dev/vitest/9492/issue_layout
twitter:imagehttps://opengraph.githubassets.com/e47a33d090612667b0457af758c731f8794f9b8b184d6dcb157f6fbb6ea476c7/vitest-dev/vitest/issues/9492
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/e47a33d090612667b0457af758c731f8794f9b8b184d6dcb157f6fbb6ea476c7/vitest-dev/vitest/issues/9492
og:image:altClear and concise description of the problem In our project, we have a need to use isolate: false and fileParallelism: false in vitest. We have seen that under this configuration, the number of vit...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameandrewbrennanfr
hostnamegithub.com
expected-hostnamegithub.com
None56fb42677ae87ed3e64410323d67980aa65d0485568a7858f874e7edfc6d1c11
turbo-cache-controlno-preview
go-importgithub.com/vitest-dev/vitest git https://github.com/vitest-dev/vitest.git
octolytics-dimension-user_id95747107
octolytics-dimension-user_loginvitest-dev
octolytics-dimension-repository_id434708679
octolytics-dimension-repository_nwovitest-dev/vitest
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id434708679
octolytics-dimension-repository_network_root_nwovitest-dev/vitest
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release9c9a37e2423ed382cf39f70b5aa4b4858b40a3b0
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/vitest-dev/vitest/issues/9492#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fvitest-dev%2Fvitest%2Fissues%2F9492
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fvitest-dev%2Fvitest%2Fissues%2F9492
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=vitest-dev%2Fvitest
Reloadhttps://github.com/vitest-dev/vitest/issues/9492
Reloadhttps://github.com/vitest-dev/vitest/issues/9492
Reloadhttps://github.com/vitest-dev/vitest/issues/9492
vitest-devhttps://github.com/vitest-dev
vitesthttps://github.com/vitest-dev/vitest
Codehttps://github.com/vitest-dev/vitest
Issues334 (334)https://github.com/vitest-dev/vitest/issues
Pull requests25 (25)https://github.com/vitest-dev/vitest/pulls
Discussionshttps://github.com/vitest-dev/vitest/discussions
Actionshttps://github.com/vitest-dev/vitest/actions
Projectshttps://github.com/vitest-dev/vitest/projects
Security and quality10 (10)https://github.com/vitest-dev/vitest/security
Insightshttps://github.com/vitest-dev/vitest/pulse
https://github.com/vitest-dev/vitest
New issuehttps://github.com/login?return_to=https://github.com/vitest-dev/vitest/issues/9492
New issuehttps://github.com/login?return_to=https://github.com/vitest-dev/vitest/issues/9492
Featurehttps://github.com/vitest-dev/vitest/issues?q=type:"Feature"
#11092https://github.com/vitest-dev/vitest/pull/11092
vi.fn "memory leak" with isolate: falsehttps://github.com/vitest-dev/vitest/issues/9492#top
#11092https://github.com/vitest-dev/vitest/pull/11092
enhancement: pending triagehttps://github.com/vitest-dev/vitest/issues?q=state%3Aopen%20label%3A%22enhancement%3A%20pending%20triage%22
https://github.com/andrewbrennanfr
andrewbrennanfrhttps://github.com/andrewbrennanfr
on Jan 20, 2026https://github.com/vitest-dev/vitest/issues/9492#issue-3834031589
as we simply loop over all active mockshttps://github.com/vitest-dev/vitest/blame/main/packages/spy/src/index.ts#L634
https://stackblitz.com/edit/vitest-dev-vitest-y6nkb7na?file=vite.config.ts,test%2Ftest01.test.ts,vitest.setup.ts,test%2Ftest05.test.ts,test%2Ftest04.test.ts&initialPath=__vitest__/https://stackblitz.com/edit/vitest-dev-vitest-y6nkb7na?file=vite.config.ts,test%2Ftest01.test.ts,vitest.setup.ts,test%2Ftest05.test.ts,test%2Ftest04.test.ts&initialPath=__vitest__/
Code of Conducthttps://github.com/vitest-dev/vitest/blob/main/CODE_OF_CONDUCT.md
Contributing Guidelineshttps://github.com/vitest-dev/vitest/blob/main/CONTRIBUTING.md
docshttps://vitest.dev/guide/
andrewbrennanfrhttps://github.com/andrewbrennanfr
enhancement: pending triagehttps://github.com/vitest-dev/vitest/issues?q=state%3Aopen%20label%3A%22enhancement%3A%20pending%20triage%22
on Jan 20, 2026https://github.com/vitest-dev/vitest/issues/9492#event-22163411449
andrewbrennanfrhttps://github.com/andrewbrennanfr
Featurehttps://github.com/vitest-dev/vitest/issues?q=type:"Feature"
on Jan 20, 2026https://github.com/vitest-dev/vitest/issues/9492#event-22163411627
oz6unhttps://github.com/oz6un
on Aug 19, 2026https://github.com/vitest-dev/vitest/issues/9492#event-29685546074
Stop re-importing one app graph 253 times, and stop replaying it on P…https://github.com/derive-to/derive/commit/b1aa2f21fedd7ec456804d8959057cd586dc7a54
b1aa2f2https://github.com/derive-to/derive/commit/b1aa2f21fedd7ec456804d8959057cd586dc7a54
https://github.com/MikeDabrowski
MikeDabrowskihttps://github.com/MikeDabrowski
on Aug 26, 2026https://github.com/vitest-dev/vitest/issues/9492#issuecomment-5422210831
sheremet-vahttps://github.com/sheremet-va
completedhttps://github.com/vitest-dev/vitest/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
#11092https://github.com/vitest-dev/vitest/pull/11092
on Sep 2, 2026https://github.com/vitest-dev/vitest/issues/9492#event-30439968927
https://github.com/sdjayna
sdjaynahttps://github.com/sdjayna
on Sep 13, 2026https://github.com/vitest-dev/vitest/issues/9492#issuecomment-5651735852
#11092https://github.com/vitest-dev/vitest/pull/11092
nodejs/node#66011https://github.com/nodejs/node/issues/66011
https://issues.chromium.org/issues/560730175https://issues.chromium.org/issues/560730175
https://chromium-review.googlesource.com/c/v8/v8/+/8397811https://chromium-review.googlesource.com/c/v8/v8/+/8397811
#11092https://github.com/vitest-dev/vitest/pull/11092
hubothttps://github.com/hubot
on Sep 15, 2026https://github.com/vitest-dev/vitest/issues/9492#event-31194049725
[objects] Hash the instance type into the NormalizedMapCache indexhttps://github.com/v8/v8/commit/d6fd1b3dd2485c688acfeaa6f4f98239e406924e
d6fd1b3https://github.com/v8/v8/commit/d6fd1b3dd2485c688acfeaa6f4f98239e406924e
github-actionshttps://github.com/apps/github-actions
on Sep 28, 2026https://github.com/vitest-dev/vitest/issues/9492#event-31953798398
Sign up for freehttps://github.com/signup?return_to=https://github.com/vitest-dev/vitest/issues/9492
Sign in to commenthttps://github.com/login?return_to=https://github.com/vitest-dev/vitest/issues/9492
enhancement: pending triagehttps://github.com/vitest-dev/vitest/issues?q=state%3Aopen%20label%3A%22enhancement%3A%20pending%20triage%22
Featurehttps://github.com/vitest-dev/vitest/issues?q=type:"Feature"
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.