Skip to content

-mm=rc/own: a global object literal { s: mk() } is freed at start #461

Closed

Description

@ASDAlexander77

Under -mm=rc and -mm=own, a module-level object literal whose field is a call result is freed at start.

class Node {
    name = "";
}

function mk() {
    const n = new Node();
    n.name = "made" + 1;
    return n;
}

let o = { s: mk() };

function main() {
    let keep: string[] = [];
    for (let i = 0; i < 1000; i++) keep.push("k" + i);
    print(o.s.name);
}

Expected: made1.

Actual, tslang --emit=jit --no-default-lib, main 8b9d631:

  • gc: made1.
  • rc: k15.
  • own: k21. Freed memory, reused by the keep loop.

The same literal as a local (const o = { s: mk() } inside main) prints made1 under rc. So the problem is the global initializer not taking over the field's reference. This is related to #459 (a Node | null global initialised from a call) but is a different shape. Found by the review of Shared<T> (own phase 8), where a global { s: mkS() } holding a handle crashes the same way.

🤖 Generated with Claude Code

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions