Skip to content

ffi: fast buffer path leaks V8 handles on every optimized call #66866

Open

Description

@trivikr

Version

main

Platform

macOS

Subsystem

ffi

What steps will reproduce the bug?

import { dlopen } from 'node:ffi';

const { functions: { strlen } } = dlopen(null, {
  strlen: { arguments: ['buffer'], return: 'u64' },
});

const kind = process.argv[2] ?? 'view';
const ab = new ArrayBuffer(16); // zero-filled, so strlen() returns 0n
const arg = kind === 'arraybuffer' ? ab : new Uint8Array(ab);

function hot(x) { return strlen(x); }

const mb = () => Math.round(process.memoryUsage().rss / 2 ** 20);
const before = mb();
for (let i = 0; i < 2e7; i++) hot(arg);
console.log(`${kind}: rss ${before} MB -> ${mb()} MB after 2e7 calls`);

Run with

$ node --no-warnings repro.mjs view

$ node --no-warnings repro.mjs arraybuffer

How often does it reproduce? Is there a required condition?

Always

What is the expected behavior? Why is that the expected behavior?

RSS stays flat, as it does for an ArrayBuffer argument. A call that only reads a backing-store pointer should not keep allocating memory.

What do you see instead?

view: rss 50 MB -> 675 MB after 2e7 calls
arraybuffer: rss 50 MB -> 60 MB after 2e7 calls

That is about 32 bytes per call for ArrayBufferView arguments.

Additional information

No response

Activity

  1. self-assigned this
    on Oct 20, 2026
  2. added
    ffiIssues and PRs related to experimental Foreign Function Interface support.
    on Oct 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

ffiIssues and PRs related to experimental Foreign Function Interface support.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions