From b372db643b9ff9c67f9edaa59e942517e7b501a7 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Mon, 21 Sep 2026 22:12:38 +0200 Subject: [PATCH 1/2] fix: reword add-on unloading paragraph - main thread add-ons are never unloaded - worker thread add-on loading is deterministic, not GC-driven Refs: https://github.com/nodejs/learn/pull/44 --- pages/node-api/special-topics/context-awareness.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pages/node-api/special-topics/context-awareness.md b/pages/node-api/special-topics/context-awareness.md index 88e76d4..7d7df64 100644 --- a/pages/node-api/special-topics/context-awareness.md +++ b/pages/node-api/special-topics/context-awareness.md @@ -14,7 +14,7 @@ Each Worker Thread operates within its own environment which is also referred to If your native add-on requires persistent memory, allocating this memory in static global space is a recipe for disaster. Instead, it is _essential_ that this memory is allocated each time within the context in which the native add-on is initialized. This memory is typically allocated in your native add-on's `Init` method. But in some cases it can also be allocated as your native add-on is running. -In addition to the multiple loading described above, your native add-on is also subject to automatic unloading by the JavaScript runtime engine's garbage collector when your native add-on is no longer in use. To prevent memory leaks, any memory your native add-on has allocated _must_ be freed when your native add-on is unloaded. +Add-ons loaded in worker threads are unloaded when the last thread that has them loaded terminates (add-ons loaded on the main Node.js thread persist for the lifetime of the process.) To prevent memory leaks, any memory your native add-on has allocated _must_ be freed when your native add-on is unloaded. The next sections describe two different techniques you can use to allocate and free persistent memory associated with your native add-on. The techniques may be used individually or together in your native add-on. From 85fca5306c014b4ce1aff81c702b2541891f682e Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Tue, 22 Sep 2026 20:17:53 +0200 Subject: [PATCH 2/2] squash! update example code comment --- pages/node-api/special-topics/context-awareness.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pages/node-api/special-topics/context-awareness.md b/pages/node-api/special-topics/context-awareness.md index 7d7df64..04f27a8 100644 --- a/pages/node-api/special-topics/context-awareness.md +++ b/pages/node-api/special-topics/context-awareness.md @@ -73,8 +73,7 @@ static int ModifyAddonData(AddonData* data, double offset) { } // This is boilerplate. The instance of the `AddonData` structure created during -// addon initialization must be destroyed when the addon is unloaded. This -// function will be called when the addon's `exports` object is garbage collected. +// addon initialization must be destroyed when the addon is unloaded. static void DeleteAddonData(napi_env env, void* data, void* hint) { // Avoid unused parameter warnings. (void) env;