Skip to content

Memory leak when instantiating arktype validators #1584

@VanTanev

Description

@VanTanev

Report a bug

Memory leak when an arktype validator is instantiated, even with something as simple as type("string"), and anything else that instantiates a type, like type.pick() or type.and(other).

Memory does not leak on type.to(other), or type.keyof()

🔎 Search Terms

OOM, memory leak

🧩 Context

  • ArkType version: 2.1.29
  • TypeScript version (5.1+): 5.9.3
  • Other context you think may be relevant (JS flavor, OS, etc.):
    Node 24.13.0

🧑‍💻 Repro

// test-arktype-memory.ts
import { type } from "arktype";
// import { z } from "zod";

const BATCH = 1_000;
let i = 0;

while (true) {
  { 
    testArkType();
  }
  if (++i % BATCH === 0) {
    i = 0
    global.gc?.();
    console.log(
      `${(process.memoryUsage().heapUsed / 1024 / 1024).toFixed(2)} MB`,
    );
  }
}

// function testZod() {
//   z.string().transform((x) => parseInt(x)).parse('1');
// }

function testArkType() {
  type("string")('1');
}

Run with: node --expose-gc --no-warnings test-arktype-memory.ts

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

Status

To do

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions