V8 libuv and runtime boundaries
Prerequisite: node-node-api-and-native-abi. Objective: Trace allocation and I/O. Tested locally on Node.js 22.16.0 Linux. Each example is independent. Use a fresh disposable working directory, save as main.mjs, then run node main.mjs. The harness uses a five-second timeout and synthetic environment. These are static code blocks, not ByteMind interactive execution.
How it works
A V8 isolate has its own JavaScript heap; worker threads use separate isolates. Objects become eligible for garbage collection when unreachable, but collection timing is not predictable. Some memory, including backing stores for buffers, is outside the ordinary JS heap. v8.getHeapStatistics() exposes heap information, while process.memoryUsage() gives process-oriented counters. A filesystem promise delegates work through Node and libuv, then a completion allows JavaScript to resume. Not every I/O operation uses the libuv worker pool: socket readiness can be handled by OS facilities. Distinguish public observations from implementation internals and avoid claiming one snapshot proves a leak.
Read heap counters without collecting private data
import {getHeapStatistics} from 'node:v8';import assert from 'node:assert/strict';const h=getHeapStatistics(),m=process.memoryUsage();assert.ok(h.heap_size_limit>0 && m.rss>0 && m.heapUsed>=0);console.log('heap and process counters available');Expected output:
heap and process counters availableThese are actual runtime counters but the fixture intentionally prints no machine-dependent sizes.
Trace an asynchronous file result
import {writeFile,readFile,unlink} from 'node:fs/promises';import assert from 'node:assert/strict';await writeFile('sample.txt','catalog');try{const pending=readFile('sample.txt','utf8');console.log('scheduled');const text=await pending;assert.equal(text,'catalog');console.log(text);}finally{await unlink('sample.txt');}Expected output:
scheduledcatalogJavaScript continues after scheduling the read; awaiting the result resumes after completion. This does not trace the native scheduling internals.
Common mistakes
Do not infer a leak from one RSS reading, or assume every asynchronous API creates a new JavaScript thread.
Practice
Draw the API → Node binding → native/OS work → completion → promise continuation path; distinguish observations from implementation claims.
Reference candidate: node-v8-libuv-and-runtime-boundaries-lookup (route unverified). Documentation: https://nodejs.org/download/release/v22.16.0/docs/api/v8.html (opened); https://nodejs.org/download/release/v22.16.0/docs/api/process.html (opened).
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
V8 libuv and runtime boundaries — knowledge check
Apply the lesson to a fresh scenario and explain the evidence boundary.
Which component executes JavaScript?
Why can RSS exceed heapUsed?
Does the promise read prove which native thread performed it?