Skip to content

fix(WeakRefObjectMap): make delete consistent with has for dead entries#40509

Draft
Copilot wants to merge 2 commits intoweakref-object-map-main-firstfrom
copilot/sub-pr-40467
Draft

fix(WeakRefObjectMap): make delete consistent with has for dead entries#40509
Copilot wants to merge 2 commits intoweakref-object-map-main-firstfrom
copilot/sub-pr-40467

Conversation

Copy link
Contributor

Copilot AI commented Feb 28, 2026

delete delegated directly to this.map.delete(key), bypassing liveness checks, so it returned true for GC'd entries while has returned false for the same key. All existing tests masked this because they called has/get first, which pruned dead entries before delete ran.

Changes

  • WeakRefObjectMap.ts: Use this.has(key) (the public method, which runs isLiveOrDelete) before delegating to the internal map:

    // Before
    delete(key: string): boolean {
      return this.map.delete(key);
    }
    
    // After — consistent with has()
    delete(key: string): boolean {
      return this.has(key) && this.map.delete(key);
    }

    Dead entries now return false from both has and delete (and are pruned by delete itself). Behavior is unchanged for live entries and non-existent keys.

  • WeakRefObjectMap.test.ts: Added a test that calls delete directly on a dead entry without any prior has/get call, covering the previously-undetected inconsistency.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: MajorLift <34228073+MajorLift@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix memory leak issue in WeakRefObjectMap fix(WeakRefObjectMap): make delete consistent with has for dead entries Feb 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants