Skip to content

InternPool and AstPool are Copy handles over raw allocations that nothing frees: every init leaks (the LSP leaks 1 MB per reparse) #2449

Closed

Description

@ehartford

InternPool and AstPool are impl Copy handles over raw with_alloc blocks (src/InternPool.w:86, src/Ast.w:829): a 256-byte state block, two HashMaps, and an InternStringArena whose first page is 1 MB (INTERN_PAGE_SIZE, src/InternPool.w:37,45). No Drop, no free, no owner: every InternPool.init() leaks by construction, and the language cannot see it because the handle is a Copy wrapper built in unsafe library-tier code. The mission says leaking is a defect that must take deliberate, visible effort; here freeing is impossible and leaking takes none.

Where it bites today

  • src/Lsp.w:473 LspDocument.ensure_parsed calls InternPool.init() on every reparse of an open document, and LspDocument.new creates two more (fast_intern, cached_intern, lines 453/457), plus AstPool.new() each time: an editor session leaks at least 1 MB per edit, for as long as the server runs.
  • 18 InternPool.init() sites in src/ (and 14 AstPool.new()), most of them placeholders: Codegen.w:641,654,1108,1109, main.w:2572,3999,4273,4304, Parse.w:26, Lsp.w:741.
  • Found 2026-10-18 when a placeholder Sema in ComptimeEval.w (PR D120 merge-gate measurement against the pre-CoW compiler: the last-use view-edge regression (1.093 → 1.032), corpus A/B tool, parser hang #2448) called InternPool.init() once per comptime evaluation: behav_1944_comptime_snapshot_memory (a 32 MB WITH_MEMORY_LIMIT_BYTES) went red (committed=33424048 requested=1048592). That caller now reuses the taken Sema's handles; the class remains.

Fix shape

  1. InternPool and AstPool become owned values (resource type, impl Drop freeing the pages, the maps and the state block) with one owner per compilation (Zcu/Compilation, the LSP document); everyone else borrows &InternPool / &AstPool (today they are passed by value as Copy handles to Parser, Sema, MirLower, Codegen, the analyze tools: hundreds of signatures).
  2. Until then, no new InternPool.init() / AstPool.new() outside the one creation site per compilation; a placeholder reuses the live handles (the comptime_take_sema precedent).
  3. A pin: a long-running with lsp session's RSS after N reparses of the same document is flat (or the debug allocator's leak report on a program that creates and drops an InternPool).

Related: D111/D120 (a Copy type must not own memory without a count), #1944.

Activity

  1. added a commit that references this issue on Oct 18, 2026
  2. added a commit that references this issue on Nov 28, 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

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions