Skip to content

Commit bd04fc8

Browse files
mhdawsonsxa
authored andcommitted
doc: clarify persistent ref behavior
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]>
1 parent 288f627 commit bd04fc8

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

doc/api/n-api.md

+8-1
Original file line numberDiff line numberDiff line change
@@ -1645,7 +1645,14 @@ the corresponding object on the heap being retained forever.
16451645
16461646
There can be multiple persistent references created which refer to the same
16471647
object, each of which will either keep the object live or not based on its
1648-
individual count.
1648+
individual count. Multiple persistent references to the same object
1649+
can result in unexpectedly keeping alive native memory. The native structures
1650+
for a persistent reference must be kept alive until finalizers for the
1651+
referenced object are executed. If a new persistent reference is created
1652+
for the same object, the finalizers for that object will not be
1653+
run and the native memory pointed by the earlier persistent reference
1654+
will not be freed. This can be avoided by calling
1655+
`napi_delete_reference` in addition to `napi_reference_unref` when possible.
16491656
16501657
#### `napi_create_reference`
16511658

0 commit comments

Comments
 (0)