Browse Source

Clarify finalizer rescue behavior in Guide

pull/1319/head
Sami Vaarala 8 years ago
parent
commit
d90f2d3357
  1. 17
      website/guide/finalization.html

17
website/guide/finalization.html

@ -60,12 +60,17 @@ finalizer are also silently ignored.</p>
<li>Finalizers are also executed for all remaining objects, regardless of <li>Finalizers are also executed for all remaining objects, regardless of
their reachability status, when a Duktape heap is destroyed.</li> their reachability status, when a Duktape heap is destroyed.</li>
<li>A finalizer is called exactly once, at the latest when the heap is <li>A finalizer is called exactly once, at the latest when the heap is
destroyed, unless the object is rescued by the finalizer by making destroyed, unless the object is rescued by making it reachable again.
it reachable again. An object may be rescued an arbitrary number of An object may be rescued by its own finalizer, or by another object's
times; the finalizer is called exactly once for each "rescue cycle". finalizer when mark-and-sweep finalizes an object. For example, if
Even with this guarantee in place, it's best practice for a finalizer <code>X.ref = Y</code>, and both X and Y become unreachable, it's
to be re-entrant and carefully avoid e.g. freeing a native resource possible for Y's finalizer to run, and later on X's finalizer to rescue
multiple times if re-entered.</li> both X and Y.</li>
<li>An object may be rescued an arbitrary number of times; the finalizer
is called exactly once for each "rescue cycle". Even with this
guarantee in place, it's best practice for a finalizer to be re-entrant
and carefully avoid e.g. freeing a native resource multiple times if
re-entered.</li>
<li>A finalizer is not executed for a Proxy object, but is executed for <li>A finalizer is not executed for a Proxy object, but is executed for
the plain target object. This ensures that a finalizer isn't executed the plain target object. This ensures that a finalizer isn't executed
multiple times when Proxy objects are created.</li> multiple times when Proxy objects are created.</li>

Loading…
Cancel
Save