From 6847fec38433a1dd16d9e3d0915e2b7fa32692c1 Mon Sep 17 00:00:00 2001 From: Michael Dawson Date: Thu, 17 Feb 2022 13:49:51 -0500 Subject: [PATCH] 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 PR-URL: https://github.com/nodejs/node/pull/42035 Reviewed-By: James M Snell Reviewed-By: Mohammed Keyvanzadeh --- doc/api/n-api.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/doc/api/n-api.md b/doc/api/n-api.md index 909e7d88ea6f4b..4a67c680372b33 100644 --- a/doc/api/n-api.md +++ b/doc/api/n-api.md @@ -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`