Skip to content

Memory leak: parser state grows across parses #137

Closed

Description

@aeberhart

The Parser instance is cached per thread (Jsonata.getParser() uses a ThreadLocal) and reused for every expression that is parsed on that thread. However, parse() does not reset the parser's per-parse state:

  • ancestry (list of parent % symbols) keeps growing with every parsed expression that uses the parent operator
  • ancestorIndex / ancestorLabel keep counting up
  • errors accumulates across parses

In long-running applications that parse many expressions, ancestry grows without bound and keeps old AST nodes reachable.

In the JS reference implementation these are local to each parser invocation (parser.js), so they should be reset at the start of each parse() call.

Reproduce:

Jsonata j1 = jsonata("items.[name, % .currency]");
// j1.parser.ancestry.size() == 1
Jsonata j2 = jsonata("items.[name, % .currency]");
// j2.parser.ancestry.size() == 2 (same thread-local parser)

Activity

  1. added this to the 0.9.11 milestone on Nov 17, 2026
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions