MCPcopy Index your code
hub / github.com/nodejs/node / gcUntil

Function gcUntil

test/common/gc.js:52–65  ·  view source on GitHub ↗

* Repeatedly triggers garbage collection until a specified condition is met or a maximum number of attempts is reached. * This utillity must be run in a Node.js instance that enables --expose-gc. * @param {string|Function} [name] - Optional name, used in the rejection message if the condition is n

(name, condition, maxCount = 10, gcOptions)

Source from the content-addressed store, hash-verified

50 * @returns {Promise} A promise that resolves when the condition is met, or rejects after 10 failed attempts.
51 */
52async function gcUntil(name, condition, maxCount = 10, gcOptions) {
53 for (let count = 0; count < maxCount; ++count) {
54 await setImmediatePromisified();
55 if (gcOptions) {
56 await global.gc(gcOptions);
57 } else {
58 await global.gc(); // Passing in undefined is not the same as empty.
59 }
60 if (condition()) {
61 return;
62 }
63 }
64 throw new Error(`Test ${name} failed`);
65}
66
67// This function can be used to check if an object factor leaks or not,
68// but it needs to be used with care:

Callers 15

runGCTestsFunction · 0.85
testFinalizeAndWrapFunction · 0.85
runAsyncTestsFunction · 0.85
runTestFunction · 0.85
runGCTestsFunction · 0.85
nested_wrap.jsFile · 0.85
runTestsFunction · 0.85
test-ffi-calls.jsFile · 0.85

Calls 1

conditionFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…