Search code examples
v8

In V8, would a non-assigned `Escape`d handle be a target of garbage collection immediately?


There're two functions: one called make_a_handle Escapes a handle with EscapableHandleScope, and another one called do_something has its own HandleScope. Assuming the do_something function calls the make_a_handle, and never assigns nor uses the Escaped handle; would the Escaped handle be a target of garbage collection immediately, or live until the destruction of the do_something's HandleScope?


Solution

  • The latter. An EscapableHandleScope's Escape function internally uses an "escape slot", which is essentially a handle in the outer HandleScope.

    For clarity, I'd also like to point out that when a HandleScope is destructed, objects referred to by its handles (assuming that was the last reference to them) will not be freed immediately; they only become eligible for garbage collection, which means they will be freed in the next garbage collection cycle.