Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
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 <mdawson@devrus.com>
  • Loading branch information
mhdawson committed Feb 17, 2022
commit 7ab1196cb67354eda832b4aae117e147ed191c06
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 to the
is created for the same object, the finalizers for that object will not be
run and the native memory from the earlier persistent reference will
Comment thread
mhdawson marked this conversation as resolved.
Resolved
not be freed. This can be avoided by calling `napi_delete_reference`
in addition to `napi_reference_unref` when possible.
Comment thread
mhdawson marked this conversation as resolved.
Resolved

#### `napi_create_reference`

Expand Down