Open Bug 1912748 Opened 1 year ago Updated 1 year ago

Garbage Collector skip a detached span element which has only WeakRef

Categories

(Core :: JavaScript: GC, defect, P5)

Firefox 129
defect

Tracking

()

UNCONFIRMED

People

(Reporter: gholk, Unassigned, NeedInfo)

References

(Blocks 1 open bug)

Details

Attachments

(1 file)

Attached file dom-gc-test2.html

First, I am not sure whether a WeakRef's target can not be reclaimed or a memory leak in js is a bug.

I am building a UI library for hobby, and face this bug in firefox.
I use WeakRef to make ui elements could be reclaim,
but I notice that with WeakRef they are still alive.

Please find the example code in the attachment.
Step:

  1. The attachment creates 3 object/element and make only WeakRef to them.
  2. When user click the button, it will show whether the WeakRef's target object is still alive.
  3. Do something to trigger the GC, like click button in about:memory
  4. The first span element is not reclaimed, though it was not referenced by anything, too

Condition to reproduce is a little complicate:

  1. They must be dom object, elements or text nodes.
  2. The WeakRef is created from the function argument and capture with a closure.
  3. The function is bind to a EventTarget (but not the window)

I write some details in the attachment's js comment.

The Bugbug bot thinks this bug should belong to the 'Core::JavaScript: GC' component, and is moving the bug to that component. Please correct in case you think the bot is wrong.

Component: Untriaged → JavaScript: GC
Product: Firefox → Core

Steve, could looking into this GC bug and help triage it? Since it has a test case that could make this actionable.

Flags: needinfo?(sphink)
Severity: -- → S4
Priority: -- → P5
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: