Open Bug 887915 Opened 11 years ago Updated 1 year ago

Provide a robust and reusable weak pointer

Categories

(Core :: JavaScript Engine, defect)

defect

Tracking

()

People

(Reporter: sfink, Unassigned)

References

(Blocks 1 open bug)

Details

I don't know if this is even possible, but it would be nice to have an easily reusable weak pointer implementation within Spidermonkey. Beyond just not keeping things alive, I'm not sure what the interface needs to be -- can it just NULL out the pointers, or do we need a finalization callback? If a callback, what state is the to-be-finalized object in? Is the weak pointer for gcthings or C++ data structures?

We already have WeakMaps, and one version of a weak pointer would be an always-live WeakMap, but our current implementation isn't really set up for heavy use, and it seems like a weak pointer could be simpler.

The design would need to come from the actual needs, so I'll record the one I know of: bug 887077 could use a weak pointer to a same-compartment JSObject* element. I think NULLing the pointer would be good enough. A callback would provide an opportunity to capture some identifying information before the element goes away, but it'd require lots of reachable stuff to still be alive and usable during the callback.

Can anyone else fill in existing or desired uses for weak pointers in the engine? I had the impression there were a bunch, but I don't know what they are.
Assignee: general → nobody
I'm not sure if this bug has enough useful info in it, but this is something we've been talking about recently and I just stumbled across this ancient bug. Linking to GC.stability; feel free to mark it INVALID or dupe it to a more useful bug.
Blocks: GC.stability
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.