diff options
author | Michael Dawson <mdawson@devrus.com> | 2022-02-17 13:49:51 -0500 |
---|---|---|
committer | Danielle Adams <adamzdanielle@gmail.com> | 2022-04-23 22:47:02 -0400 |
commit | 3d75c8748cb3b50465f6d976a4bc460324b60258 (patch) | |
tree | c49407c478c2d227fa8200e47cf33588560c8037 /doc | |
parent | 8c26d8cea1e43b697dfa10add20c6fca0f7ec6ec (diff) | |
download | node-new-3d75c8748cb3b50465f6d976a4bc460324b60258.tar.gz |
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>
PR-URL: https://github.com/nodejs/node/pull/42035
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com>
Diffstat (limited to 'doc')
-rw-r--r-- | doc/api/n-api.md | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/doc/api/n-api.md b/doc/api/n-api.md index 58ee65a1d2..284d9eb5cb 100644 --- a/doc/api/n-api.md +++ b/doc/api/n-api.md @@ -1645,7 +1645,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` |