Skip to content

Commit 6847fec

Browse files
committed
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 470c284 commit 6847fec

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
@@ -1649,7 +1649,14 @@ the corresponding object on the heap being retained forever.
16491649
16501650
There can be multiple persistent references created which refer to the same
16511651
object, each of which will either keep the object live or not based on its
1652-
individual count.
1652+
individual count. Multiple persistent references to the same object
1653+
can result in unexpectedly keeping alive native memory. The native structures
1654+
for a persistent reference must be kept alive until finalizers for the
1655+
referenced object are executed. If a new persistent reference is created
1656+
for the same object, the finalizers for that object will not be
1657+
run and the native memory pointed by the earlier persistent reference
1658+
will not be freed. This can be avoided by calling
1659+
`napi_delete_reference` in addition to `napi_reference_unref` when possible.
16531660
16541661
#### `napi_create_reference`
16551662

0 commit comments

Comments
 (0)