Skip to content

[Bug]: transformFromAstSync leaks memory #13970

Description

@JLHwung

💻

  • Would you like to work on a fix?

How are you using Babel?

Programmatic API (babel.transform, babel.parse)

Input code

for (let i = 0; i < 1e7; i++) {
    ast = babel.transformFromAstSync(ast, src, {
      configFile: false,
      ast: true,
    }).ast;
  }

For a complete reproduction, see https://github.com/JLHwung/babel-transform-from-ast-leak

Configuration file name

No response

Configuration

N.A.

Current and expected behavior

Current: The memory usage rises beyond 2GB

Expected: The memory usage should be stable during repetitive transformFromAstSync calls.

Environment

System:
OS: macOS 12.0.1
Binaries:
Node: 17.0.1 - /opt/homebrew/bin/node
Yarn: 1.22.17 - /opt/homebrew/bin/yarn
npm: 8.1.0 - /opt/homebrew/bin/npm
npmPackages:
@babel/core: ^7.16.0 => 7.16.0

Possible solution

No response

Additional context

Found this issue when running jest --detect-leaks in the Babel codebase.

transformFromAstAsync and transformFromAst are also affected.

When switching transformFromAstSync to transformSync, the memory leakage can not be reproduced.

Activity

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

    outdatedA closed issue/PR that is archived due to age. Recommended to make a new issuepkg: core

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions