Skip to content

Commit

Permalink
doc: clarify persistent ref behavior
Browse files Browse the repository at this point in the history
Add explanation of case to be careful of
in order to avoid native memory being kept
alive.

Signed-off-by: Michael Dawson <[email protected]>

PR-URL: #42035
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Mohammed Keyvanzadeh <[email protected]>
  • Loading branch information
mhdawson committed Feb 22, 2022
1 parent 470c284 commit 6847fec
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion doc/api/n-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1649,7 +1649,14 @@ the corresponding object on the heap being retained forever.
There can be multiple persistent references created which refer to the same
object, each of which will either keep the object live or not based on its
individual count.
individual count. Multiple persistent references to the same object
can result in unexpectedly keeping alive native memory. The native structures
for a persistent reference must be kept alive until finalizers for the
referenced object are executed. If a new persistent reference is created
for the same object, the finalizers for that object will not be
run and the native memory pointed by the earlier persistent reference
will not be freed. This can be avoided by calling
`napi_delete_reference` in addition to `napi_reference_unref` when possible.
#### `napi_create_reference`
Expand Down

0 comments on commit 6847fec

Please sign in to comment.