Sitelet https://github.com/nodejs/node/issues/40828
Skip to content

v8.serialize leaks memory #40828

Description

@JLHwung

Version

v17.0.1

Platform

21.1.0 Darwin Kernel Version 21.1.0: Wed Oct 13 17:33:01 PDT 2021; root:xnu-8019.41.5~1/RELEASE_ARM64_T6000 arm64

Subsystem

v8

What steps will reproduce the bug?

Run the following snippet

const { serialize } = require("v8");
const { memoryUsage } = process;

for (let i = 0; i < 1 << 22; i++) {
  serialize({});

  if (i % (1 << 15) === 0) {
    console.log(
      `RSS: ${Math.round((memoryUsage().rss / 1024 / 1024) * 100) / 100} MiB`
    );
  }
}

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

Must reproduce

What is the expected behavior?

The RSS in the stdout should converges to some tens of MiB. For example, if v8.serialize is replaced by JSON.stringify, the RSS is stablized at 33.89MiB.

What do you see instead?

The RSS keeps rising indefinitely.

Additional information

Also affected: v16.0.0

Additional context: babel/babel#13970

Activity

  1. added
    v8 moduleIssues and PRs related to the node:v8 module.
    on Nov 16, 2021
  2. cjihrig commented on Nov 16, 2021

    @cjihrig
    Contributor

    It doesn't look like you're giving the garbage collector a chance to run. Does the memory get collected once the loop is exited?

  3. JLHwung commented on Nov 16, 2021

    @JLHwung
    ContributorAuthor

    Does the memory get collected once the loop is exited?

    I still see memory surging when I invoke gc every 1 << 15 times.

    const { serialize } = require("v8");
    const { memoryUsage } = process;
    
    for (let i = 0; i < 1 << 22; i++) {
      serialize({});
    
      if (i % (1 << 15) === 0) {
        gc();
        console.log(
          `RSS: ${Math.round((memoryUsage().rss / 1024 / 1024) * 100) / 100} MiB`
        );
      }
    }
  4. ppedziwiatr commented on Jan 18, 2022

    @ppedziwiatr

    Same issue observed on various x86 CPUs and node 16.x and 17x.

    The issue doesn't seem to occur on my M1 though.

  5. added a commit that references this issue on Jul 12, 2022
  6. added a commit that references this issue on Jul 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    v8 moduleIssues and PRs related to the node:v8 module.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions