|
|
|
|
|
by ghusbands
1474 days ago
|
|
Where would the weak array be stored? Ephemerons are often used when you can't attach data directly to either the key object or the value object. It's the simplest efficient primitive that lets you encode "if object A is reachable, object B also is" without otherwise affecting the visibility of A (or B), altering A, or needing multiple GC cycles to settle. |
|
Multiple cycles are not fundamental to ephemeron collection, though. If you keep all of your unmarked keys (specifically, keys of ephemeron tables that have been marked) in a lookup table, then in theory every time you mark anything you could look it up in that table to see if you need to traverse an ephemeron edge. In practice, you probably don't want to do those lookups until you've traversed the "easy" part of the heap that doesn't require traversing ephemerons to get to.
Source: that's how I implemented it in SpiderMonkey: https://searchfox.org/mozilla-central/rev/552bfc6334b797d92f...