Skip to content

Memory leak in 4.0.18 causing OOM when running multiple tests #9560

Description

@natew

Describe the bug

vitest 4.0.18 has a memory leak when running multiple tests in sequence, causing OOM (Out of Memory) errors. Downgrading to 4.0.4 resolves the issue.

Reproduction

The tamagui monorepo has a reproduction of this issue:

Steps to reproduce:

  1. Clone https://github.com/tamagui/tamagui at commit 3ac968be38 (using vitest ^4.0.18)
  2. Run bun install && bun run build:js
  3. Run cd code/compiler/static-tests && bun run test:babel:web
  4. Observe OOM error after running 27 tests

With vitest 4.0.4 (commit 9a8381a175), the same tests pass in ~1 second without any memory issues.

System Info

Node.js v24.3.0
macOS Darwin 25.2.0
vitest 4.0.18 (broken)
vitest 4.0.4 (working)

Used Package Manager

bun

Expected behavior

Tests should run without OOM errors regardless of the number of tests being run.

Actual behavior

After running ~20+ tests, the process runs out of memory and crashes with:

FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory

Additional context

  • This only occurs when running multiple tests in the same session
  • Individual tests pass fine
  • Memory accumulates across tests, suggesting workers/processes aren't being cleaned up properly
  • Adding --max-old-space-size=8192 or --no-file-parallelism doesn't help
  • The issue appeared after upgrading from 4.0.4 to 4.0.18

Validations

  • Check that there isn't already an issue that reports the same bug
  • The provided reproduction is minimal and self-contained

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions