There're two functions: one called make_a_handle
Escape
s 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 Escape
d handle; would the Escape
d handle be a target of garbage collection immediately, or live until the destruction of the do_something
's HandleScope
?
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.