Issue with FinalizationRegistry or gc
Either FinalizationRegistry or garbage collection is not working as expected for me.
Minimally reproducible example:
// file: test.js
(async () => {
const loggingFinalizer = new FinalizationRegistry((x) => { console.log('FINALIZING', x) });
{
let obj = { name: 'John' };
loggingFinalizer.register(obj, obj.name);
obj = null;
}
if ('tjs' in globalThis) globalThis.tjs.engine.gc.run();
if ('gc' in globalThis) globalThis.gc();
await new Promise((r) => setTimeout(r, 1000));
})();
Should be logging FINALIZING John, but exits after 1s.
Works as expected in Deno: deno run -A --v8-flags=--expose-gc ./test.js
Commit d6f9888d671f2f729b7e6c2e92f8c67f8db38e85 on macOS arch64
In quickjs { name: 'John'} will not be deleted by the garbage collection, but by the reference counter.
Not sure if this is the reason.
I'll take a look. I'm QuickJS GC is implemented with refcounting and cycle detection.
I wonder if what happens is that GC sees both the finrec and obj and collects them at the same time.
Moved issue to QuickJS-ng.