-
TLTR: is there a way to force GC in the current version of Node? I'm looking at using So I'm experimenting with a version of The full code gist is here. I'm struggling to come up with a deterministic test for this in Node. Even when I call Is there a more predictable way of forcing GC in Node? I'm using the latest v15.4.0. OTOH, I'm able to test it in the browser, the finalizers gets called when I click the Trash icon ("Collect garbage") in the Performance section of DevTools. So, for browsers, I should be able to automate this with Puppeteer. Thanks for any help! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Forcing? Not really. You could try the natives syntax function |
Beta Was this translation helpful? Give feedback.
-
If anyone else ends up here, I had to:
Any other way and the weak refs were not cleaned up. e.g., test('cleaned', async () => {
const w = weak();
await new Promise(resolve => setTimeout(resolve, 0));
global.gc();
expect(w.deref()).toEqual(null);
});
function weak() {
return new WeakRef({});
} |
Beta Was this translation helpful? Give feedback.
Forcing? Not really. You could try the natives syntax function
%CollectGarbage
but I believe that has the same impact as callingglobal.gc()